使用Maven 3时,Cobertura代码覆盖率为0%

时间:2011-11-04 10:20:01

标签: java maven-3 pom.xml cobertura

看完之后: What is the proper way to use Cobertura with Maven 3.0.2 还有这个: http://www.wakaleo.com/blog/292-site-generation-in-maven-3

我的POM文件如下所示:

    <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我得到了不好的结果。

3 个答案:

答案 0 :(得分:1)

好的,问题解决了。奇怪的是,经过一些刷新和重建后,一切都开始正常工作。 Ser文件存在于目录中,现在所有报告都正确生成。我对此非常惊讶:)

答案 1 :(得分:1)

好的,我发现在父pom中配置特殊执行或者完全使用父节点时,可能必须在maven-surefire-plugin的配置部分明确地包含** / * Test.java。 ....其他它在cobertura执行期间根本没有执行任何万无一失的测试,报告总是显示零覆盖。

答案 2 :(得分:0)

我没有尝试将maven-cobertura-plugin作为maven-site-plugin的一部分运行。

我确实通过将maven-cobertura-plugin从'build'转移到'reporting'来直接工作,如我在这里的回答: Why cobertura reports code coverage as zero for all but one module in multi-module maven project?