Using Cobertura with Maven
Posted by doubleA on February 26, 2007
Configuring Cobertura is quite easy with Maven. You need to add two entries to your pom.xml.
First, add the following to your build section:
-
<plugin>
-
<groupId>org.codehaus.mojo</groupId>
-
<artifactId>cobertura-maven-plugin</artifactId>
-
<executions>
-
<execution>
-
<goals>
-
<goal>clean</goal>
-
<goal>check</goal>
-
</goals>
-
</execution>
-
</executions>
-
<configuration>
-
<instrumentation>
-
<includes>
-
<include>**/*.class</include>
-
</includes>
-
<excludes>
-
<exclude>**/*Test.class</exclude>
-
<exclude>**/Base*.class</exclude>
-
<exclude>**/*Filter.class</exclude>
-
<exclude>**/NTLM*.class</exclude>
-
</excludes>
-
</instrumentation>
-
<check>
-
<totalLineRate>70</totalLineRate>
-
<totalBranchRate>70</totalBranchRate>
-
</check>
-
</configuration>
-
</plugin>
The plugin allows you to setup your coverage thresholds and any include/excludes. In this example, I’m excluding all of my test cases, and anything related to base abstract classes. I’m also excluding NTLM code because that is not currently used in the project and there are no test cases for the code.
Second, setup a reporting plugin so Cobertura will generate its reports when the Maven site is generated:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>