Unable to get integration test coverage in SonarQube

2,508 views
Skip to first unread message

karl.mich...@gmail.com

unread,
Jan 20, 2018, 7:52:47 PM1/20/18
to SonarQube
Howdy all,

Been banging my head against this for a few hours, and I'm hopeful someone can point me in the right direction. I recently upgraded to a current version of SonarQube, and I've been unable to get it to include my integration test coverage in its calculations. In my Maven POMs, I've got this:

    <properties>
        <!-- Configure SonarQube to analyze both unit and integration test results. -->
        <sonar.junit.reportPaths>target/surefire-reports,target/failsafe-reports</sonar.junit.reportPaths>
    </properties>

    <build>
       
<pluginManagement>
            <plugins>
               
<plugin>
                    <!-- A test code coverage plugin that can operate as a Java agent (and
                        thus doesn't require class file instrumentation). -->

                   
<groupId>org.jacoco</groupId>
                   
<artifactId>jacoco-maven-plugin</artifactId>
                   
<version>0.8.0</version>
                   
<configuration>
                       
<!-- Configure JaCoCo to write unit and integration test coverage data to
                            the same file. There's no reason to separate them, really, since SonarQube
                            doesn't make a distinction between the phases. -->

                       
<append>true</append>
                       
<destFile>${project.build.directory}/jacoco.exec</destFile>
                   
</configuration>
                </plugin>
            </plugins>
       
</pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- Will set the 'argline' Maven property to point to the JaCoCo runtime
                            agent (configured to track information on unit test coverage), such that
                            it can be passed as a VM argument to the application under test. Surefire
                            will pick up this property automatically, by default. Sonar can then pick
                            up the output produced by JaCoCo. -->
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <!-- Will set the 'argline' Maven property to point to the JaCoCo runtime
                            agent (configured to track information on integration test coverage), such
                            that it can be passed as a VM argument to the application under test. Failsafe
                            will pick up this property automatically, by default. Sonar can then pick
                            up the output produced by JaCoCo. -->
                        <id>default-prepare-agent-integration</id>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- Ensure that this project's integration tests are run as part of
                    the build. -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

And here's what I'm running in my Jenkinsfile to build and push to SonarQube:
        mvn "--update-snapshots -Dmaven.test.failure.ignore=true clean deploy"
        withSonarQubeEnv('justdavis-sonarqube') {
            mvn "org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar"
        }

Some background:
  • My ITs are all in the same project & module as the code under test.
  • The unit tests are named **/*Test.java.
  • The ITs are named **/*IT.java.


If I run 'mvn clean verify && mvn org.jacoco:jacoco-maven-plugin:report' on the command line, I get a JaCoCo report with a combined coverage of 59%. However, when this all lands in Sonar, I end up with a coverage of 43%, and no indication that my ITs were considered at all.

Anyone know what might be going on?

Thanks much!
Karl M. Davis

karl.mich...@gmail.com

unread,
Jan 21, 2018, 12:37:45 AM1/21/18
to SonarQube
Howdy all,

Disregard my question: PEBKAC (problem exists between keyboard and chair).

Turns out the IT coverage is being counted, but is just way different in SonarQube's calculations than in the jacoco-maven-plugin's.

Apologies,
Karl M. Davis
Reply all
Reply to author
Forward
0 new messages