Cobertura code coverage is 0% when using Maven 3

Arek picture Arek · Nov 4, 2011 · Viewed 8.3k times · Source

After reading this: What is the proper way to use Cobertura with Maven 3.0.2 and this: http://www.wakaleo.com/blog/292-site-generation-in-maven-3

my POM file looks like this:

    <build>
    <plugins>
        .....
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.7</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jxr-plugin</artifactId>
                        <version>2.1</version>
                        <configuration>
                            <aggregate>true</aggregate>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-report-plugin</artifactId>
                        <version>2.6</version>
                        <configuration>
                            <skip>true</skip>
                            <useFile>false</useFile>
                            <argLine>-Xmx512m</argLine>
                            <systemProperties>
                                <property>
                                    <name>generateReport</name>
                                    <value>html</value>
                                </property>
                            </systemProperties>
                        </configuration>
                        <executions>
                            <execution>
                                <id>unit-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <includes>
                                        <include>**/UnitTest*.java</include>
                                        <include>**/*UnitTest.java</include>
                                        <include>**/*Scenarios.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                            <execution>
                                <id>integration-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>${integrationTestsSkip}</skip>
                                    <includes>
                                        <include>**/*IntegrationTest.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <instrumentation>
                                <includes>
                                    <include>**/UnitTest*.class</include>
                                    <include>**/*UnitTest.class</include>
                                    <include>**/*Scenarios.class</include>
                                </includes>
                            </instrumentation>
                        </configuration>
                        <executions>
                            <execution>
                                <id>clean</id>
                                <phase>pre-site</phase>
                                <goals>
                                    <goal>clean</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>instrument</id>
                                <phase>site</phase>
                                <goals>
                                    <goal>instrument</goal>
                                    <goal>cobertura</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.6</version>
                    </plugin>
                </reportPlugins>
            </configuration>
        </plugin>

        ......



    </plugins>
</build>

After running cobertura:cobertura i still don't get any reports. In target cobertura folder is empty and there is no folder called site. Can anyone tell me what did I do wrong? When i was using older approach with maven 2.2 everything worked fine yet with M3 i got bad results.

Answer

Arek picture Arek · Nov 7, 2011

Ok, problem solved. Strangely after a few refreshes and rebuilds everything started to work just fine. Ser file was present in directory and now all reports are generated correctly. I am pretty astonished by that :)