Jacoco unit and integration tests code coverage

Hello,

We are using sonarqube version 8.9 and jacoco-maven-plugin version 0.8.7.
We also use maven-sueerfire-plugin for unit tests and maven-failsafe-plugin for integration tests.

Maven config is the following:

<jacoco.version>0.8.7</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>java</sonar.language>
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml, target/site/jacoco-it/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

org.jacoco jacoco-maven-plugin ${jacoco.version} prepare-agent prepare-agent-integration report report-integration

The reported coverage in sonarqube seems to be showing the combined coverage of both unit and integration tests. However in the left menu, I can only see Unit Tests, when I click on this link I can see the number of unit tests. Is it also possible to show the number of integration tests ? Why are they not all together so we can have a full overview of test classes ?

Thanks,
Lucas

Hi,

Welcome to the community!

Yes, coverage from all types is aggregated.

This is labeled Unit Tests because that’s typically what the reports about the tests themselves cover. There’s not a way to have a second set of numbers that’s just about your ITs.

 
HTH,
Ann

Hello Ann,

Thank you for your answer, however when I look under unit tests, I only see the unit tests listed, not the integration tests. Maybee it’s a detail but just want to make sure the coverage is accurate.

Kind regards,
Lucas

Hi Lucas,

Coverage doesn’t have a lot to do with the test execution report.

 
Ann

Hi,
I observed the same effect than Lucas did.

Does the anwser to his question change ?

I use Jacoco 0.8.10, maven-failsafe-plugin 3.1.2, maven-surefire-plugin 3.1.2, sonar-maven-plugin 3.10.0.2594, maven 3.8.6, open jdk 19, sonar sonarqube-10.2.1.78527.zip

I found a work around but it would be better to use the failsafe plugin.

The work around is to configure the surefire plugin to include **/*Test.java and **/*IT.java files and to use the build-helper-maven-plugin and to add src/it/java as test sources.