删除冗余的 JUnit 测试套件测试
在我们的 JUnit 测试套件中,我发现一些测试不会提高覆盖率,因此应该删除(它们需要时间,但并没有真正为测试套件增加价值)。
我想知道有哪些工具可以为我发现多余的测试?
In our JUnit testsuite, I have spotted a few tests that do not drive up coverage, and thus should be removed (they take time but does not really add value to the test suite).
I was wondering what tools exist that can spot redundant tests for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是对代码覆盖率指标的滥用。仅仅因为测试不会增加指标,它不一定是多余的 - 它可以测试由 LOC 组成的特定执行路径,这些 LOC 被多个其他测试一起覆盖,但代表其他测试都没有覆盖的行为。请记住:代码行为很大程度上受状态影响,但我知道没有测试覆盖率工具可以测量状态空间的覆盖率。
除非测试套件的运行时是一个严重的问题,否则您可以用时间做比消除可能冗余的测试更好的事情。
I'd consider this a misuse of the code coverage metric. Just because a test doesn't increase the metric, it is not necessarily redundant - it could test a specific execution path that consists of LOC that are covered by several other tests together, but represents behaviour that none of the other tests cover. And remember: code behaviour is influenced very much by state, but no test coverage tool I know measures the coverage of state space.
Unless the runtime of your test suite is a serious problem, there are much better things you can do with your time than eliminate possibly redundant tests.
几个月前,我使用了 Eclipse 插件 Clover。它可以显示每行代码被执行了多少次,并在单元测试后突出显示。我认为 Clover 可以在这一点上帮助你。
Some months ago I used Eclipse plugin Clover. It could show how many times each line of code be executed and highlight after unit tests. I think Clover could help you at this point.