本文介绍了单元测试的遗留代码:极限"提取和越权QUOT; VS JustMock / TypeMock /痣?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 一个很老的,大的,C#遗留代码基础,没有testcoverage任何

  • (几乎)每一个类从一些接口

  • 派生什么是密封

什么是使用像JustMock和TypeMock探查-API驱动的解决方案的实际利益,相对于使用提取和放大器;覆盖+例如: RhinoMocks的?有没有我不知道的情况下,除了规避私人/保护,在使用TypeMock / JustMock等确实的需要的?我特别欢迎人们的一些经验已经切换到产品之一。

What are the practical benefits of using profiler-API-driven solutions like JustMock and TypeMock, compared to using extract&override + e.g. RhinoMocks? Are there cases I'm not aware of, besides circumventing private/protected, where using TypeMock/JustMock etc. is really needed? I'd especially welcome some experience from people having switched to one of the products.

使用提取和放越权似乎解决所有的问题处理旧的遗留代码,重构似乎死的时候简单,引入错误的可能性似乎非常轻微。是利益少写测试代码?更多美丽的班,少虚保护的东西?现在,我不'明白',虽然我知道这是非常有益的,以孤立第一次测试的私有方法,因为公有方法可能是在这样的旧的遗留代码库的引擎盖下太大。

Using extract&override seems to solve all problems when handling old legacy code, the refactoring seems dead simple, and the possibility for introducing bugs seems very minor. Is the benefit writing less test code? More beautifull classes with less virtual protected stuff? Right now, I don't 'get it', although I understand it's very helpfull to first test private methods in isolation, as public methods may be too large under the hood in such old legacy codebases.

如果你不知道该怎么提取物和放大器是覆盖:看的。

If you don't know what extract&override is: see here.

推荐答案

有哪些不需要方面的框架之间的许多不同之处。在该框架建立在技术

There are many differences between the frameworks which do not regard the technology on which the frameworks built on.

例如:


  • API - 每个框架有不同的符号和默认值(如
    严格违约与放松默认)

  • 支持 - 在恰当的框架通常与许可证提供支持

  • 价格 - 这不是用法的问题,但需要预算

提取物&放大器的主要优点;覆盖是,它需要一些重构,如果你正在处理的代码被忽视,它提供了一个很好的机会去在它与重构它朝着更好的代码而不是只为可测试性。

The main advantage of Extract&Override is that it requires some refactoring, if the code you're working on is neglected, it's gives a good chance to go over it and refactor it toward better code and not just for testability.

使用隔离框架的主要优点是,你不需要测试更改代码(如果它是一个大的代码库,它可能需要很长一段时间只是为了重构它可测性)。此外,隔离框架不强迫你进入具体的设计,如果遗留代码更好地匹配现有的设计,这可能是有帮助的。另一个特点是在传统的代码是有用的测试换在代码中创建的实例,通常重构实例需要更多的努力,这可以被保存。最后一件事是伪造第三方代码 - 使用隔离框架,您可以隔离代码,这是不是你不使用包装类

The main advantage of using an Isolation framework is that you do not need to change the code under test (if it's a large codebase it could take long time just to refactor it for testability). In addition, the Isolation frameworks do not force you into specific design, this could be helpful if the legacy code matches better its existing design. Another feature which is useful in legacy code is swapping instances created in the code under test, usually refactoring instantiations takes more effort and this can be saved. Last thing is faking 3rd party code - using isolation frameworks you can isolate code which is not yours without using wrapper classes.

免责声明 - 我在Typemock

这篇关于单元测试的遗留代码:极限"提取和越权QUOT; VS JustMock / TypeMock /痣?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:39