8

我正在使用 maven cobertura 插件来报告我的多模块项目中的代码覆盖率。

问题是我不知道如何为项目中的所有模块生成一份报告。

到目前为止,我已经为每个模块生成了单独的报告,但是为整个项目提供一份报告会很好。

我的父 pom 配置:

   <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <inherited>true</inherited>
        <executions>
            <execution>
                <phase>test-compile</phase>
                <goals>
                    <goal>clean</goal>
                    <goal>cobertura</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
4

4 回答 4

18

自从提出这个问题(并最后回答)以来,插件已经更新,现在通过aggregate父 POM 中的配置属性启用聚合报告。

target/site/cobertura/index.html这将生成包含所有模块的聚合覆盖率报告。

(如果有任何用处,每个模块也会生成自己的报告。)

父 pom.xml

<modules>
    <module>moduleA</module>
    <module>moduleB</module>
    <module>moduleC</module>
<modules>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <check/>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                    <aggregate>true</aggregate>
                </configuration>
            </plugin>
            ...
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
...
</build>
于 2013-09-23T13:19:43.423 回答
2

据我所知,目前不支持此功能,请参阅MCOBERTURA-65。但是这个问题有一个补丁,也许可以试试。但我的建议是使用声纳之类的东西来汇总指标。

于 2010-09-22T16:08:51.677 回答
0

我一直在使用 Hudson 作为持续集成工具。Cobertura 插件允许我在检查父模块时查看所有子模块的代码覆盖率。

于 2011-01-19T19:50:08.440 回答
0

Jenkins Cobertura 插件会自动聚合报告,但如果您出于其他原因对覆盖文件本身感兴趣,您可以按照以下步骤进行操作:

  1. 从这里下载 Cobertura

  2. 转到您的项目工作区-> 找到所有.ser文件并重命名它们

    (i=0; find . | grep cobertura.ser$ | while read line;do echo $line; cp -i $line cobertura$i.ser;i=$(($i+1));done;)
    
  3. 用于cobertura-merge.sh生成全局.ser文件

    ~/cobertura-2.0.3/cobertura-merge.sh --datafile cobertura.ser cobertura*.ser
    
  4. 用于 cobertura-report.sh生成关于全局 .ser 文件的报告

    ~/cobertura-2.0.3/cobertura-report.sh ./cobertura.ser --destination ./ --format xml
    

您将coverage.xml在当前目录中生成全局。您可以将其用于进一步的任何类型的处理。

于 2013-08-24T00:32:58.343 回答