DoTaL

My repository for development tidbits, and a few personal anecdotes

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:

  1.       <plugin>
  2.         <groupId>org.codehaus.mojo</groupId>
  3.         <artifactId>cobertura-maven-plugin</artifactId>
  4.         <executions>
  5.           <execution>
  6.             <goals>
  7.               <goal>clean</goal>
  8.               <goal>check</goal>
  9.             </goals>
  10.           </execution>
  11.         </executions>
  12.         <configuration>
  13.           <instrumentation>
  14.             <includes>
  15.               <include>**/*.class</include>
  16.             </includes>
  17.             <excludes>
  18.               <exclude>**/*Test.class</exclude>
  19.               <exclude>**/Base*.class</exclude>
  20.               <exclude>**/*Filter.class</exclude>
  21.               <exclude>**/NTLM*.class</exclude>
  22.             </excludes>
  23.           </instrumentation>
  24.           <check>
  25.             <totalLineRate>70</totalLineRate>
  26.             <totalBranchRate>70</totalBranchRate>
  27.           </check>
  28.         </configuration>
  29.       </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>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>