简体   繁体   English

使单元测试快速失败以进行突变测试

[英]Making unit tests fail quickly for mutation testing

One problem encountered with mutation testing is that it's slow, because by default you do a full test run (either a test file, or a suite of test files) for each mutation generated. 突变测试遇到的一个问题是它很慢,因为默认情况下,您会为生成的每个突变执行完整的测试运行(测试文件或一组测试文件)。

One way to make mutation testing faster would be to stop the test run for a given mutant once a single failure has been encountered (but only during mutation testing). 使突变测试更快的一种方法是在遇到单个故障时停止针对给定突变体的测试运行(但仅在突变测试期间)。 Even better would be for the mutation tester to remember what was the first test to kill the last mutant, and give that first to the next mutant. 甚至更好的是突变测试仪要记住什么是第一个杀死最后一个突变体的测试,并首先将其给予下一个突变体。 Is there anything in ruby that does either of these things, or is my best bet to start monkey patching? 红宝石中是否有任何东西可以做这些事情,或者是我开始修补猴子的最佳选择?

(Yes, I know unit tests ought to be fast. And showing all of the failed tests is useful outside of mutation testing, as it helps you not merely identify that something's wrong, but pinpoint where it's going wrong) (是的,我知道单元测试应该很快。并且显示所有失败的测试在突变测试之外是有用的,因为它不仅可以帮助您识别出错误,还可以确定哪里出错了)

Edit : I'm currently using heckle with test/unit. 编辑 :我目前正在使用测试/单位的heckle。 If it's not possible for test/unit to remember which tests fail between runnings, maybe heckle or something running heckle could remember it. 如果测试/单元无法记住哪些测试在运行之间失败,那么heckle或者运行heckle的东西就能记住它。

My mutant tool uses the rspec2 --fail-fast option to stop immediately once a failing example was encountered. 一旦遇到失败的示例,我的突变工具使用rspec2 --fail-fast选项立即停止。 Together with the --rspec-dm2 strategy that only executes affected unit tests we get very fast mutation coverage testing. 与仅执行受影响的单元测试的--rspec-dm2策略一起,我们可以获得非常快速的变异覆盖测试。 See this asciicast for a (speed) demonstration. 请参阅此asciicast进行(速度)演示。

Your best best is to check out the heckle source from github, patch it, and submit that patch to the developers. 你最好的方法是从github查看heckle源码 ,修补它,并将该补丁提交给开发人员。 You ought to be able to write a custom test runner for heckle. 你应该能够为heckle编写一个自定义测试运行器。

Monkey patching is never the answer for something like this. 猴子补丁永远不会是这样的答案。 In fact, monkey patching is almost never the answer for anything. 实际上,猴子补丁几乎不是任何事情的答案。

One approach I've started using was writing unit tests for each method, and putting them in separate files, organized like rubyspecs. 我开始使用的一种方法是为每个方法编写单元测试,并将它们放在单独的文件中,像rubyspecs一样组织。 I run each spec in isolation, specifying the exact method I want to heckle. 我单独运行每个规范,指定我想要解决的确切方法。 I have a rake task that manages all this and prints a report at the end with failing mutations, if any. 我有一个rake任务管理所有这些并在最后打印一个报告失败的突变,如果有的话。

In the end I get full heckle coverage of each method, without waiting forever for the results. 最后,我得到了对每种方法的全面覆盖,无需等待结果。 Plus it's even better than the normal approach everyone uses, because I don't get any incidental coverage -- each methods's specs must cover all mutations of that method. 此外,它甚至比每个人使用的正常方法更好,因为我没有得到任何附带的报道 - 每个方法的规范必须涵盖该方法的所有突变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM