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:
How can it be that overall coverage is lower?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With