使用 Maven 3 时,Cobertura 代码覆盖率为 0% [英] Cobertura code coverage is 0% when using Maven 3

查看:99
本文介绍了使用 Maven 3 时,Cobertura 代码覆盖率为 0%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读本文后:正确的方法是什么将 Cobertura 与 Maven 3.0.2 一起使用和这个:http://www.wakaleo.com/blog/292-site-generation-in-maven-3

我的 POM 文件如下所示:

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>

运行 cobertura:cobertura 后,我仍然没有收到任何报告.在目标 cobertura 文件夹中是空的,并且没有名为 site 的文件夹.谁能告诉我我做错了什么?当我在 maven 2.2 中使用旧方法时,一切正常,但在 M3 中我得到了糟糕的结果.

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.

推荐答案

好吧,我发现在配置时可能必须在 maven-surefire-plugin 的配置部分中明确包含 **/*Test.java父 pom 中的特殊执行或根本使用父 pom 时..... 否则它在 cobertura 执行期间根本没有执行任何可靠的测试,并且报告始终显示零覆盖率.

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.

这篇关于使用 Maven 3 时,Cobertura 代码覆盖率为 0%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆