Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cobertura code coverage is 0% when using Maven 3

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.

like image 859
Arek Avatar asked Nov 04 '11 10:11

Arek


2 Answers

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 :)

like image 141
Arek Avatar answered Oct 12 '22 18:10

Arek


Ok, what I have found it is that one might have to explicitly include **/*Test.java in the maven-surefire-plugin's configuration section when configuring special executions in the parent pom or when using a parent at all..... otherweise it did not execute any surefire tests at all during the cobertura execution and the reports always showed zero coverage.

like image 41
user1050755 Avatar answered Oct 12 '22 19:10

user1050755