热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

Oneproblemencounteredwithmutationtestingisthatitsslow,becausebydefaultyoudoafullte

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. 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或者运行heckle的东西就能记住它。

3 个解决方案

#1


2  

Your best best is to check out the heckle source from github, patch it, and submit that patch to the developers. You ought to be able to write a custom test runner for heckle.

你最好的方法是从github查看heckle源码,修补它,并将该补丁提交给开发人员。你应该能够为heckle编写一个自定义测试运行器。

Monkey patching is never the answer for something like this. In fact, monkey patching is almost never the answer for anything.

猴子补丁永远不会是这样的回答。事实上,猴子补丁几乎不是任何事情的答案。

#2


2  

My mutant tool uses the rspec2 --fail-fast option to stop immediately once a failing example was encountered. Together with the --rspec-dm2 strategy that only executes affected unit tests we get very fast mutation coverage testing. See this asciicast for a (speed) demonstration.

我的突变工具使用rspec2 --fail-fast选项在遇到失败的示例后立即停止。与仅执行受影响的单元测试的--rspec-dm2策略一起,我们可以获得非常快速的变异覆盖测试。请参阅此asciicast进行(速度)演示。

#3


1  

One approach I've started using was writing unit tests for each method, and putting them in separate files, organized like 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.

我开始使用的一种方法是为每个方法编写单元测试,并将它们放在单独的文件中,组织起来像rubyspecs。我单独运行每个规范,指定我想要解决的确切方法。我有一个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.

最后,我得到了对每种方法的全面覆盖,而不必永远等待结果。此外,它甚至比每个人使用的正常方法更好,因为我没有得到任何偶然的报道 - 每个方法的规范必须涵盖该方法的所有突变。


推荐阅读
author-avatar
手机用户2502883515
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有