Mismatch between the coverage percentage generated locally and the percentage displayed in the UI

Jacoco report which generated locally by developer and sonarqube UI coverage which imports the report and display the coverage isn’t the same. What could be the reason for such behaviour.
The Jacoco report which generated locally,it shows 87%


were as in UI the coverage is 77.2%

what could be the reason for the mismatch
Thanks
Shivashree

Hi Shivashree,

Great question—this trips up a lot of folks integrating JaCoCo with SonarQube! The coverage numbers differ because SonarQube calculates coverage differently.

Your local JaCoCo report shows 87.7%, which is just line coverage (covered lines ÷ total lines). SonarQube, though, uses both line and branch coverage. Its formula is:

Coverage = (Covered Branches + Covered Lines) / (Total Branches + Total Lines)

In your case:

  • Covered Lines: 1672
  • Total Lines: 1905
  • Covered Branches: 560
  • Total Branches: 984

So, (560 + 1672) / (984 + 1905) ≈ 77.3%. That’s why SonarQube shows a lower percentage—it counts missed branches too, not just missed lines.

(docs)

Hope this clears things up!

Cheers.

1 Like