Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar false overall coverage (jacoco)

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?

like image 865
orshachar Avatar asked Mar 12 '15 18:03

orshachar


1 Answers

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.

like image 193
orshachar Avatar answered Oct 19 '22 22:10

orshachar