Sonar false total coverage (jacoco)

I am running Jacoco and Sonar in a multi-module Java8 project. I have unit tests in each of the modules and to save resources I collect all the "integration tests" into one "integration test runner" and run them there (wrapping them before and after the tests).

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

When I run the sonar, I reuse these exec files, specifying the path to jacoco-it.exec.

I get a very strange image: enter image description here

How can the overall coverage be lower?

+6
source share
2 answers

I found a problem and solution.

From the Sonar website, I see this :

By default, when a coverage report is not found, the JaCoCo plugin will not set any value for the coverage metric. This behavior can be exceeded by up to 0% if there is no 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 installed sonar.jacoco.itReportPath from the parent pom, then all modules were analyzed to cover integration tests and coverage in general .

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

+6
source

Why is this weird? Block and integration tests execute code, and some executable code fragments overlap. In other words, the code covered by the module and the integration tests are not disjoint, so you cannot just add them.

0
source

Source: https://habr.com/ru/post/983717/


All Articles