The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Maven Test Coverage : Cobertura and Surefire working

Posted by survivant on November 11, 2008 at 5:45 AM PST

I wanted to add Cobertura to Grizzly project within the pom file for Maven, but I got errors at first.

I follow the procedure describe on Cobertura website, but it was lacking of a complete example. Cobertura will instrument your classes and you need to run tests to get a test coverage. You need to pass the path of these instrumented classes to the plugin that will run the tests(in the same pattern for ant and junit).

For my project I'm using Surefire.

I created a file pom2.xml for Grizzly. Put this file in the root of the project and call it like that : mvn -f pom2.xml cobertura:cobertura

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        <groupId>com.sun.grizzly</groupId>
        <artifactId>grizzly-project</artifactId>
        <version>1.9.0-SNAPSHOT</version>
        <relativePath>pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sun.grizzly</groupId>
    <artifactId>grizzly-framework</artifactId>
    <version>${grizzly-version}</version>
    <name>grizzly-framework</name>
    <url>https://grizzly.dev.java.net</url>
    <build>
        <plugins>
            <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>clean</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <systemProperties>
                                    <property>
                                    <name>net.sourceforge.cobertura.datafile</name>
                                    <value>target/cobertura/cobertura.ser</value>
                                    </property>
                                </systemProperties>
                            </configuration>
                        </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <version>2.1</version>
                        </plugin>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-report-plugin</artifactId>
                                <version>2.0</version>
                            </plugin>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>2.2</version>
                            </plugin>
        </plugins>
    </reporting>
</project>

I put explicit version of the plugins. You can remove that to use the latest version.

Related Topics >> Programming      
Comments
Comments are listed in date ascending order (oldest first)

Great blog! Why not committing the file in Grizzly directly :-)

Well, this is Maven main problem. Lack of Documentation.