mvn网站构建过程中的Maven2 Multiproject Cobertura报告问题 [英] Maven2 Multiproject Cobertura Reporting Problems During mvn site Build

查看:101
本文介绍了mvn网站构建过程中的Maven2 Multiproject Cobertura报告问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为mvn网站构建的一部分,我们有一个多项目正在尝试运行Cobertura测试覆盖率报告.我可以让Cobertura在子项目上运行,但是它错误地报告了0%的覆盖率,即使报告仍然突出显示了单元测试中遇到的代码行.

We've got a multiproject we're trying to run Cobertura test coverage reports on as part of our mvn site build. I can get Cobertura to run on the child projects, but it erroneously reports 0% coverage, even though the reports still highlight the lines of code that were hit by the unit tests.

我们正在使用mvn 2.0.8.我尝试运行mvn clean sitemvn clean site:stagemvn clean package site.我知道测试正在运行,它们显示在surefire报告(txt/xml和站点报告)中.我在配置中缺少什么吗? Cobertura是否不适用于多项目?

We are using mvn 2.0.8. I have tried running mvn clean site, mvn clean site:stage and mvn clean package site. I know the tests are running, they show up in the surefire reports (both the txt/xml and site reports). Am I missing something in the configuration? Does Cobertura not work right with multiprojects?

这在父.pom中:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <id>clean</id>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <inherited>true</inherited>
        </plugin>
    </plugins>
</reporting>

我尝试在子.poms中使用以下命令来运行它:

I've tried running it with and without the following in the child .poms:

    <reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
</reporting>

我在构建的输出中得到了这个

I get this in the output of the build:

...
[INFO] [cobertura:instrument]
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Instrumenting 3 files to C:\workspaces\sandbox\CommonJsf\target\generated-classes\cobertura
Cobertura: Saved information on 3 classes.
Instrument time: 186ms

[INFO] Instrumentation was successful.
...
[INFO] Generating "Cobertura Test Coverage" report.
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 3 classes.
Report time: 481ms

[INFO] Cobertura Report generation was successful.

该报告如下所示:

推荐答案

我怀疑您在编译阶段缺少执行cobertura插件的过程,因此在站点生命周期中,仅由报告插件来检测代码,运行测试后.因此不会进行测试,因为它们是在非仪器代码上运行.更加仔细地分析构建日志-如果我是对的,您会注意到surefire测试是在cobertura:instrument之前执行的.

I suspect that you're missing an execution of cobertura plugin during the compile phase so that the code only gets instrumented by the reporting plugins, in the site lifecycle, after the tests were run. So the test runs aren't picked up because they run on non-instrumented code. Analyze your build logs more carefully - if I'm right, you'll notice that surefire tests are executed before cobertura:instrument.

我的配置与您的配置相似,但是除了在pluginManagement中指定干净的执行方式(像您一样)之外,我还在build plugins部分中显式指定了cobertura插件:

My configuration is similar to yours, but in addition to specifying the clean exectution in pluginManagement (like you), I specify the cobertura plugin explicitly in build plugins section:

  <build>
  ...
    <plugins>
    ...
      <plugin>
        <inherited>true</inherited>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>${cobertura.plugin.version}</version>
      </plugin>
    </plugins>
  </build>

我的配置排序有效,并且所有Cobertura内容都在全球组织范围的pom中,所有项目都将其用作父项.

My configuration sorta works, and all Cobertura stuff is in the global organization-wide pom, which all projects use as a parent.

这样,项目不会在pom.xml中指定任何与Cobertura相关的内容,但是它们仍会生成覆盖率报告.

This way projects don't specify anything Cobertura-related in their pom.xml's, but they still generate coverage reports.

这篇关于mvn网站构建过程中的Maven2 Multiproject Cobertura报告问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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