使用 Maven 运行 junits 和 cobertura

发布于 2024-07-17 15:55:43 字数 378 浏览 15 评论 0原文

在我们的项目中,我们使用 Maven 运行 junits 和 cobertura。 我面临的问题是,

  1. junit 测试用例运行两次,一次在 jar 创建过程之前,然后再次生成 cobertura 覆盖率报告。 当使用 ant 运行 cobertura 和 junits 时,我们只运行一次 junits,因为 cobertura 与 junits 一起运行。 有没有办法用maven配置上面的情况。 我知道我们可以使用“maven.test.skip”属性来跳过 junit。 但是当我这样做时,我看不到 junit xml & html 文件报告。
  2. 另外,在maven中如何配置junits以批量或并行运行?

谢谢你!

In our project, we run both junits and cobertura using maven. The problem I am facing is that,

  1. junit test cases are running twice, once before the jar creation process and then once again for generating cobertura coverage reports. When running cobertura and junits with ant, we run junits only once since, cobertura runs along with junits. Is there a way to configure the above case with maven. I know we can use "maven.test.skip" property to skip junits. But when I do this, I am not able to see junit xml & html file reports.
  2. Also, in maven how to configure junits to run in batch or parallel ?

thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

私藏温柔 2024-07-24 15:55:43

虽然我再也找不到确切的页面,但我最近阅读了一篇关于为什么运行测试两次被认为是一个好主意的讨论。 引用的关键问题是 Cobertura 字节码更改对测试准确性的影响。 在某些情况下,代码执行的时间可能很重要,字节码更改可能会导致在 JUnit 中失败的测试在仅在 Cobertura 中运行时通过,反之亦然。 因此,建议允许测试执行两次。 引用的大多数示例都是围绕多线程行为,但我想可能还有其他情况,字节码更改可能会导致测试中出现问题。 以两种方式执行测试可以为您提供基线结果,并且如果 Cobertura 实际上正在改变测试成功,还可以减少让您白费力气的机会。

While I cannot find the exact page anymore, I recently read a discussion of why running the tests twice is considered a good idea. The key issues cited were around the effects of the Cobertura byte code alteration on the accuracy of your tests. In certain cases the timing of your code execution might be important, the byte code alteration can cause tests that fail in JUnit to pass when run only in Cobertura and vice versa. For this reason, it was recommended that the tests be allowed to execute twice. Most of the examples cited were around multi-threaded behaviors, but I imagine that there could be other cases were the byte code alteration can cause issues in your tests. Having the tests execute both ways provides you with baseline results and also reduces the chances of sending you on a wild goose chase if Cobertura is in fact altering test success.

呆头 2024-07-24 15:55:43

尝试添加 cobertura 作为编译范围参考。 并发布你的 pom 的相关部分。

Try adding cobertura as a compile scope reference. And post the relevant parts of your pom.

情绪 2024-07-24 15:55:43

发生这种情况是因为报告执行需要测试执行才能创建报告。 如果站点插件上有一个“仅站点”目标,并且没有 @requiresDependencyResolution test 注释,则它可以绑定到项目的 prepare-package 阶段并且无需运行两次测试即可生成您的报告。

不幸的是,目前似乎没有这样的目标(请参阅我关于该主题的问题 )。
有关解决方法的详细信息,请参阅我对问题的回答。

This happens because the reporting execution requires the test execution so it can create the reports. If there were a "site-only" goal on the site plugin that didn't have the @requiresDependencyResolution test annotation, it could be bound to the project's prepare-package phase and your reports would be generated without the tests running twice.

Unfortunately there seems to currently be no such goal (see my question on the subject).
See my answer to the question for details of a workaround.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文