Jacoco test-coverage is not equal to Sonarqube coverage

880 views
Skip to first unread message

akri...@gmail.com

unread,
Feb 22, 2018, 5:45:13 AM2/22/18
to SonarQube
Hi,

I try to setup sonarqube properly but I'm struggling with the code coverage. By using the gradle jacoco plugin I get an exec file and an html report. Within the html report I have a code coverage for certain lines that are tested indirectly (running integration tests).

If I check sonarqube after I pushed the exec file to sonarqube then I see another coverage result. My guess is that Sonarqube only shows unit test covergage because these lines, that are only covered by integration tests, have no coverage.

Is there anything that I miss? I would like to see the overall coverage and not only the unit test coverage.

I am using Sonarqube 7.0.0.36138, Sonarqube-gradle-plugin 2.5, org.jacoco.core-0.7.1 to do the analysis and the sonar push.

Does someone have an idea how I can fix this flaw?

Regards
Sebastian

G. Ann Campbell

unread,
Feb 22, 2018, 3:11:23 PM2/22/18
to SonarQube
Hi Sebastian,

Your situation isn't entirely clear to me. You're running both unit and integration tests and... only importing 1 of the two reports? ... importing a combined report that should reflect both types of test coverage?

Also, if you're asking because the overall coverage numbers don't match from SonarQube to JaCoCo, then you probably want to read this discussion of Executable Lines.


HTH,
Ann

akri...@gmail.com

unread,
Feb 23, 2018, 10:35:33 AM2/23/18
to SonarQube
Hi Ann,

thank you for your fast response. It's not so complicated, I have the following structure:

my-project
  -- src
  ---- main
  ------ java // here are my java files
  ---- test
  ------ java // here are my test files
  -- target
  ---- jacoco
  ------ tests.exec
  ---- htmlReport // here is my jacoco html report

If I run the gradle sonarqube task using the sonarqube gradle plugin then everything gets pushed. I see the coverage updates in sonar. It's just like they do not match. Functions that are tested indirectly are not test covered in sonarqube.

For example:

MyApplicationServicesTest contains tests for MyApplicationService. Jacoco and sonarqube contains line coverage for MyApplicationService. The implementation MyApplicationService also has some dependencies like MyEntity. Within an executed method the method MyEntity.myMethod gets called. The indirect tested method (integration test) is covered in the jacoco html report but not in sonar.

Is this intentional? Maybe it's because I am using an old jacoco plugin? Maybe there is something else wrong?

Greetings
Sebastian

G. Ann Campbell

unread,
Feb 23, 2018, 2:56:26 PM2/23/18
to akri...@gmail.com, SonarQube
Hi Sebastian,

Are you merging multiple reports (unit test + integration test) before analysis? And if so, could that process be going wrong? Because other than using Executable Lines for files that are omitted entirely from your coverage reports, we essentially pass coverage data through untouched. So if there's data missing on the SonarQube side, it's a pretty sure bet that it's either not in the report, or we're not picking up the (correct) report.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/VDQfQTLZ4cc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/366ed201-33e8-4724-8d4c-5d0441973e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages