Using Java, jacoco, maven, I got this coverage report for one file:
If you count the green lines , the red ones and the striped lines, you got:
red = uncovered = 7
striped = partly covered = 2
gree = covered = 14
now you calculate the coverage ratio:
covered+partly covered / all lines = 16 / 23 = 0.6956 = 70%
or
covered / all lines = 14 / 23 = 0.6086 = 61 %
But why does sonarcloud show a Coverage of 64,9% ?
- the Coverage HTML - Report above (same project, same files, same jacoco run) from Jacoco shows
74% Instruction coverage and 57% Branch Coverage
- the Intellij Coverage plugin (using the same jacoco.xml report as sonarcube) shows
69% line coverage (so it counts the partly covered lines also ) and
57% Branch coverage
I understand that “line” coverage is different from “instruction” coverage.
But how comes that the sonarcloud shows this odd 64,9% , what kind of coverage is this ?
Unfortunately this, discrepancy in coverage is all over our whole project with hundreds of files,
the jacoco html- report and the sonarcloud coverage does not agree in most cases , why is that ?