Integration Test Coverage with Sonar

I love to develop test driven, but even more I love code analysis tools that show me what to improve. Sonar is quite “popular” and common for Java developers and I’m using it already for years in different projects.

If you want to see integration test coverage, you have to set the jacoco maven plugin together with the fail safe plugin in your maven config (pom.xml):

    <build>
       <plugins>
            <!-- integration tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- for integration test coverage in sonar -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
      <!-- needs to be set for jacoco's forked process -->
        <argLine>${env.MAVEN_OPTS}</argLine>
    </properties>

argLine is used as additional param in the javaagent command line section jacoco uses (needs to be set, otherwise the maven opts are not set for the forked process – OutOfMemoryException and so on…). See jacoco’s documentation for details.

The result in Sonar is pretty amazing:

sonar-jacoco

Advertisements
This entry was posted in howtos and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s