使用 Cobertura Maven 插件运行集成测试
我无法让 Cobertura 插件在 Maven 中运行集成测试。我发现的这个问题最接近的答案是 http://jira.codehaus.org/browse/MCOBERTURA -86。但是,该问题仍然是一个未解决的错误。我在 09 年 4 月 3 日尝试了 Stevo 建议的配置,但没有成功。
顺便说一句,我的 POM
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
与 Stevo 提供的配置片段完全相同。
I am having trouble getting the Cobertura plugin to run integration tests in Maven. The closest answer to this question I have found is http://jira.codehaus.org/browse/MCOBERTURA-86. However, the issue remains an open bug. I tried the configuration suggested by Stevo on 03/Apr/09, it didn't work.
My POM
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura-integration</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
which is by the way exactly the same as the configuration fragment provided by Stevo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在我看来,cobertura maven 插件有两大缺点。它没有仅报告目标,所有单元测试都将再次在 Surefire 旁边运行。它仅为单元测试创建代码覆盖率。
我现在使用 JaCoCo maven 插件。 JaCoCo 重用可靠和/或故障安全报告来创建单元和/或集成测试的代码覆盖率。此外,JaCoCo 拥有良好的 Jenkins 集成。下面是 JaCoCo 使用 Surefire 单元测试和故障安全集成测试的示例。
From my opinion, the cobertura maven plugin has two big disadvantages. It has no report only goal, all unit tests will run beside surefire again. It creates the code coverage for unit tests only .
I am using the JaCoCo maven plugin now. JaCoCo reuses the surefire and/or failsafe reports to create a code coverage from unit and/or integration test. Furthermore JaCoCo has a good Jenkins integration. Here is an example where JaCoCo uses surefire unit tests and failsafe integration tests.
尝试为该插件配置一个执行阶段,就像
这样,它对我来说就像一个魅力。
Try to configure a execution phase for that plugin like
That way it works like a charm for me.
经过一番研究发现 http://jira.codehaus.org/browse/MCOBERTURA- 列出了一个工作配置 - 86
确保使用以下命令调用它
After some research found a working config listed from http://jira.codehaus.org/browse/MCOBERTURA-86
Make sure to invoke this with
对于任何通过 Google 绊倒这个问题的人 - cobertura-maven-plugin 开始支持2.7 版本中的集成测试,该版本于 2015 年发布。
引用他们的网站:
如果您像我一样,使用
mvn cobertura:cobertura
运行 cobertura 报告,则需要执行mvn cobertura:cobertura-integration-test
来还要进行集成测试。您可以从其手册页。For anyone stumbling on this question through Google - cobertura-maven-plugin started supporting integration tests in version 2.7, which was published in 2015.
Quoting their website:
If you, like I did, run cobertura report using
mvn cobertura:cobertura
, you'll need to domvn cobertura:cobertura-integration-test
to get integration tests as well. You can check the details from its manual page.我发现使用 maven-antrun-plugin 进行多模块项目(包括集成和 UI 测试)是最好的解决方案。我使用了这篇文章 降低 Ant 的目标并从那里开始。现在,我们每个模块都有代码覆盖率报告,并合并了包含所有测试覆盖率的报告。
I found that using the maven-antrun-plugin for multi-module projects including integration and UI tests is the best solution. I used this post to get the Ant goals down and went from there. We now have code coverage reports per module and merged one containing coverage from all tests.
我通过配置 maven-failsafe-plugin 在
test
阶段运行来使用 Maven 3.0.3 和 cobertura-maven-plugin 2.5.1 进行集成测试:I got the integration tests working with Maven 3.0.3 and cobertura-maven-plugin 2.5.1 by configuring the maven-failsafe-plugin to run during the
test
phase: