Cobertura code coverage is 0% when using Maven 3

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 13:15:57

问题


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.


回答1:


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




回答2:


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.




回答3:


I haven't tried running maven-cobertura-plugin as part of maven-site-plugin.

I did get it to work directly by moving maven-cobertura-plugin out of 'build' and into 'reporting', as in my answer here : Why cobertura reports code coverage as zero for all but one module in multi-module maven project?



来源:https://stackoverflow.com/questions/8007759/cobertura-code-coverage-is-0-when-using-maven-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!