Wednesday, August 13, 2014

Maven cobertura integration for JUNIT code coverage report

Add the below code inside the pom.xml

This should be under build tag
<build>
....
       <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
                                <version>2.6</version>
<configuration>
<check></check>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<instrumentation>
<ignores>
<!-- <ignore>com.cscinfo.dc.triage.solr.*</ignore> -->
</ignores>
<excludes>
                                                     <!--This is place where we can ignore the list of class which we really don't require junits -->
<exclude>com/cscinfo/dc/triage/solr/*.class</exclude>
</excludes>

</instrumentation>
</configuration>
</plugin>
Under the report tag add the below code
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>

To generate the cobertura report run
mvn cobertura:cobertura
This will generate the html report under target/site/cobertura/index.html.

No comments: