使用 maven 运行 junits 和 cobertura [英] running junits and cobertura with maven

查看:25
本文介绍了使用 maven 运行 junits 和 cobertura的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

谢谢!

推荐答案

虽然我找不到确切的页面了,但我最近阅读了一篇关于为什么将测试运行两次被认为是一个好主意的讨论.引用的关键问题是围绕 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.

这篇关于使用 maven 运行 junits 和 cobertura的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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