Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add 'test' and 'integration-test' mojos #41

@gslowikowski

Description

@gslowikowski

There are two cases in multimodule projects, when two Maven runs are required to get proper coverage data:

  • when there are separate modules for integration tests:
+- foo
|  \- src
|     +- main
|     |  \- scala
|     \- test
|        \- scala   <-- `foo` unit tests
\- foo-tests
   \- src
      \- test
         \- scala   <-- `foo` integration tests
  • when one module depends on other and its tests execute not only its code, but dependent module(s) code too:
+- foo
|  \- src
|     +- main
|     |  \- scala
|     \- test
|        \- scala  <-- `foo` unit tests
\- bar             <-- `bar` depends on `foo`
   \- src
      +- main
      |  \- scala
      \- test
         \- scala  <-- `bar` unit tests executed on `foo` and `bar` code

The problem is that Scoverage report for foo module is generated before foo-tests/bar (see above) module tests execution. While these tests are executed (on instrumented foo and foo-tests/bar code) coverage level can increase.

To get proper coverage data two Maven executions must be performed:

  • first one instrumenting classes and executing tests
  • second one generating coverage report or checking coverage minimum level.

The second execution will use scoverage:report-only and/or scoverage:check-only mojos.

What mojos should be used in the first execution? There is no mojo performing tests, without generating coverage report and checking minimum coverage level.
scoverage:report must be used, which after tests execution generates coverage report. This report will be overwritten by scoverage:report-only mojo executed in the second Maven execution.

To avoid this two new mojos will be introduced:

  • scoverage:test - instruments code and executes unit tests without coverage report generation and minimum level checking,
  • scoverage:integration-test - instruments code and executes unit and integration tests without coverage report generation and level checking,

These mojos are equivalent to scoverage:report and scoverage:integration-report without coverage report generation (or scoverage:check and scoverage:integration-check without coverage level checking).
They should be used in first Maven execution in the cases described above.

Side note - the following equations are true(*):

  • scoverage:test + scoverage:report-only = scoverage:report
  • scoverage:integration-test + scoverage:report-only = scoverage:integration-report
  • scoverage:test + scoverage:check-only = scoverage:check
  • scoverage:integration-test + scoverage:check-only = scoverage:integration-check
  • scoverage:test + scoverage:check-only + scoverage:report-only = scoverage:check + scoverage:report-only = scoverage:report + scoverage:check-only

(*) if project adds source root dynamically (e.g. using build-helper-maven-plugin add-source, sbt-compiler-maven-plugin addScalaSources or scala-maven-plugin add-source mojo) this mojo must be executed before scoverage:report-only mojo. This means executing:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions