Jacoco.exec not displaying full test coverage in SonarQube

502 views Asked by At

We have a small multi-module Java Spring REST application that is building with the maven surefire plugin. Because the application is fairly small, we wrote a mix of unit tests and integration tests and run them all as unit tests, so we get a single set of jacoco.exec files.

When I pull up the test coverage in SonarQube, the coverage is only being calculated for the module in which the test was run. So the integration tests that we have in the REST controller layer are not generating any coverage in the business or data layers.

I have tried multiple configurations of jacoco and I'm tired of staring at it. Any suggestions would be helpful.

jacoco configuration in parent pom.xml:

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                    <execution>
                            <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                           <goal>report</goal>
                        </goals>
                   </execution>
            </executions>
        </plugin>

surefire configuration in parent pom.xml:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <systemPropertyVariables>
                    <org.jboss.logging.provider>slf4j</org.jboss.logging.provider>
                </systemPropertyVariables>          
            </configuration>
        </plugin>
1

There are 1 answers

2
benzonico On

the coverage is only being calculated for the module in which the test was run

This is how the import of JaCoCo report in SonarQube works.

If you want to overcome this, you may want to merge the reports before feeding it to SonarQube.