我们有一个多项目,我们正在尝试运行 Cobertura 测试覆盖率报告,作为我们 mvn 站点构建的一部分。我可以让 Cobertura 在子项目上运行,但它错误地报告 0% 覆盖率,即使报告仍然突出显示单元测试所命中的代码行。
我们使用的是 mvn 2.0.8。我尝试过跑步mvn clean site
, mvn clean site:stage
and mvn clean package site
。我知道测试正在运行,它们显示在 Surefire 报告中(txt/xml 和站点报告)。我在配置中遗漏了什么吗? Cobertura 不适用于多项目吗?
这是在父 .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 中使用或不使用以下内容来运行它:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
我在构建的输出中得到了这个:
...
[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.
And the report looks like this:
我怀疑您在编译阶段错过了 cobertura 插件的执行,因此代码仅在测试运行后在站点生命周期中由报告插件进行检测。因此,测试运行不会被执行,因为它们在非检测代码上运行。更仔细地分析您的构建日志 - 如果我是对的,您会注意到肯定的测试是在 cobertura:instrument 之前执行的。
我的配置与您的配置类似,但除了在pluginManagement中指定干净执行(像您一样)之外,我还在构建插件部分中显式指定了cobertura插件:
<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 中,所有项目都将其用作父项目。
这样,项目就不会在其 pom.xml 中指定任何与 Cobertura 相关的内容,但它们仍然会生成覆盖率报告。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)