Sonarcloud Coverage shows very small coverage compare to Jacoco

I am having 2 Android application that has integrated with Sonarcloud. I am writing these 2 Android applications with Kotlin and Java. I and my team have strived to have unit tests in our application. And also we are striving hard to have great code coverage for these 2 applications. So far we are measuring the code coverage by looking at Jacoco coverage in our platform.

Long story short, I and my team have paid a plan in Sonarcloud, to integrate these 2 applications. So we can have better visibility of our coverage and also our code quality.

  • The first app is showing a similar coverage with Jacoco coverage. Jacoco shows 79% coverage, and Sonarcloud shows 74% coverage. And I believe it is common, since Sonarcloud has its own way to calculate coverage. And also Sonarcloud shows a similar coverage PER CLASS of this application. So I don’t have any problem with the first app.
  • The second app (THE PROBLEM) is showing a very small coverage in Sonarcloud compares to the Jacoco one. Jacoco shows 66% coverage, meanwhile Sonarcloud only shows 19.7%. I have integrated with a similar way with the first app. Jacoco’s coverage exclusion and Sonarcloud’s coverage exclusion is having the same list of classes. So I am wondering why does it produce a different result? This is the screenshot of wrong coverage, and the example of a class that have a drastic difference of coverage in Jacoco and Sonarcloud:

Some classes in the Sonarcloud is showing the similar coverages with the Jacoco one. But most of the classes shows a wrong and much more smaller coverage, almost all of them are 0 coverage. In the picture, there is 1 example of the wrong coverage in a class! It shows 86% coverage in Jacoco, but shows 0% coverage in Sonarcloud.

Notes: I have integrated the all application by using sonar.coverage.jacoco.xmlReportPaths , and enable xml jacoco report as well. I have read Jacoco XML of the second app, it reflect all the coverage that is showing in the Jacoco, but DOES NOT reflect the coverage in the Sonarcloud for some classes!

Any of you guys have experienced this problem before? Please help me with this situation, I can give more screenshots and code if needed! :slight_smile:
Thank you in advance!

Welcome to the community!

I don’t recall such issue in the past. A couple of questions come to mind:

  • Are you sure the xml file that contains report of the class where coverage is missing is was present in sonar.coverage.jacoco.xmlReportPaths?
  • Do you see anything interesting in the scanner logs related to coverage? How about if you run in debug mode? It should at least show the coverage report files that were processed, possibly some errors if something went wrong with the report processing.
  • Is the screenshot an analysis from the main branch of the project, or from a pull request analysis or short-lived branch analysis?
  • Would you be able to package a minimal reproducible example?


Hi there, this issue is really similar (same?) to what I’m observing at the moment. I’m working on on-prem installation however, version 7.9.1, tried with Gradle plugin and CLI directly, no difference.
@janos, sure, the file is there, importer does not complain:

10:07:18.622 INFO: Sensor JaCoCo XML Report Importer [jacoco]
10:07:18.632 DEBUG: Reading report ‘C:\Projects\janus\build\reports\jacoco\test\jacocoTestReport.xml’
10:07:18.675 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=53ms

what would be the minimal reproducible example? What would you need to dig into it? I’d be happy to help/
Thanks in advance

Thanks for offering help, and welcome to the community!

To dig into this I’d need some code such that if I run the analysis myself, I will get the issue that you are seeing (= coverage missing). Strictly speaking it doesn’t have to be minimal. Basically the smaller size and less external dependencies make it easier for me to reproduce and debug, with minimal noise. If you can provide a public repo to an example where it happens, that would be great. If it’s difficult to make it public, then I can open a private thread with you, just let me know!