Code Coverage showing 0 for some files

I’m facing code coverage issues with Hybris ANT. I’m performing the following steps:

  1. Created the jacoco.exec file using jacocoagent.jar.
  2. Generated the jacoco.xml report using the jacoco.exec file created in step 1.
  3. Ran the SonarQube scanner and passed the sonar.coverage.jacoco.xmlReportPaths property.

Initially, I obtained some coverage, but after adding more unit tests to increase coverage, I see 0% coverage for specific extensions/files.

Here’s how I’m generating the jacoco.exec file:

ant unittests -Dtestclasses.extensions=ext1 -Dtestclasses.reportdir=/tmp/unittests '-Dstandalone.javaoptions=-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoagent.jar=destfile=/tmp/jacoco.exec'

And here’s how I’m generating the jacoco.xml report file from the jacoco.exec file:

java -jar /tmp/jacococli.jar report /tmp/jacoco.exec --classfiles <path/to/classfiles> --xml /tmp/jacoco.xml

I’m using SonarQube Developer Edition v10.5.1.

Hey there.

Have you confirmed that this report actually shows coverage on the files you expect to see increased coverage for? SonarQube only reads the report – so if the file isn’t represented in the report or the report says there’s no coverage… SonarQube will believe it.

Yes, SonarQube reads coverage from the /tmp/jacoco.xml file only. However, when I add new test cases, SonarQube does not show the coverage. I’ve also noticed that sometimes it shows coverage for a specific file, while other times it does not.

I understand, but have you actually opened the /tmp/jacoco.xml to validate that the new coverage is being reflected in that file?

I can see new methods but it showing covered=“0”.

In that case, you’ll have to resolve that issue with your coverage report. SonarQube is just believing the data it is being given in the report.

1 Like