Blog

IT coverage with Arquillian Jacoco extension

This is a short note on how to enable coverage analysis for your Integration Tests. I will assume that you are sane developer and use maven as your build tool. For static code analysis, nice charts and all kinds of statistics I’m going to use Sonar.

For actual code coverage analysis on the sonar side we are going to use Jacoco. To get a brief comparision of coverage analysis tools available for sonar have a look here

I’m going to use JBoss Arquillian for our Integration Testing needs (for this example actually that would be in-container test of the whole persistence layer using additional arquillian extension).

Maven configuration part:

To configure your maven project and enable code coverage for your integration tests all you have to do is to add two dependencies and declare a single plugin to at least one of your existing build profiles (you can of course create a separate profile just for Jacoco if you need too)

Dependencies:

            <dependency>
                <groupId>org.jboss.arquillian.extension</groupId>
                <artifactId>arquillian-jacoco</artifactId>
                <scope>test</scope>
                <version>1.0.0.Alpha1</version>
            </dependency>
            <dependency>
                <groupId>org.jacoco</groupId>
                <artifactId>org.jacoco.core</artifactId>
                <version>0.5.3.201107060350</version>
            </dependency>

…and the plugin part..

                   <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.5.3.201107060350</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>

Sonar configuration Part

As of Sonar 2.12 you no longer need to install a separate plugin for Jacoco library, all you have to do is to enable it and configure on the sonar administration pages.
Log in as administrator, select one of your projects and go to ‘Configuration’ -> ‘Settings’.

Select ‘Code Coverage’ tab and set Jacoco as your default coverage analysis engine.

Once this is done, run your build either with sonar plugin enabled in your pom.xml or with mvn sonar:sonar and wait for your statistics.

Edit your sonar dashboard settings to see the IT coverage widget and actual statistics.

One response on “IT coverage with Arquillian Jacoco extension

  1. Mike September 11, 2012 at 3:45 pm

    Is this applicable for multi module Maven projects? Where to put the plugin then? I’ve got one integration test module for each production module.

Leave a Reply

Related Posts

    No Releated Posts