6
votes

I'm running Jacoco and Sonar on multimodule Java8 project. I have unit tests in each of the modules and to save resources I collect all 'integration tests' into one "integration-tests-runner" and run them all there (wrapping them with before and after tests).

When measuring coverage UT generates exec file per module target/jacoco-ut.exec, while the IT generates one exec file: /target/jacoco-it.exec.

When I run sonar I reuse those exec files, giving path to the jacoco-it.exec.

I get a very weird image: enter image description here

How can it be that overall coverage is lower?

2
using Sonar Java plugin 2.9.2 and jacoco plugin 0.7.3.201502191951orshachar

2 Answers

6
votes

I found the problem and the solution.

From Sonar website I see this:

By default, when no coverage report is found, the JaCoCo plugin will not set any value for coverage metric. This behaviour can be overriden to force coverage to 0% in case of a lack of report by setting the following property : sonar.jacoco.reportMissing.force.zero=true


This means that UT analysis was skipped for modules without any tests. Since I've set the sonar.jacoco.itReportPath from parent pom then all modules got analyzed for integration tests coverage, and overall coverage.

Bottom line: setting the property sonar.jacoco.reportMissing.force.zero=true from parent pom fixed the numbers.

0
votes

Why is that weird? The unit and integration tests execute code and certain executed code chunks overlap. With other words, the code which is covered by the unit and integration tests is not disjoint, thus you cannot simply add them up.