背景 本文假设你对TDD.Stub和Mock已经有了初步的认识,本文简单解释一下stub和mock的区别和使用场景,先看看他们之间的关系: 由上图可以知道mock框架可以非常容易的开发stub和mock,但是stub框架想要提高mock机制就要靠自己扩展了. Stub stub存在的意图是为了让测试对象可以正常的执行,其实现一般会硬编码一些输入和输出,下面的代码使用了MS自带的Fake和Shim来实现stub. Fake实现 using System; using Microsoft.Visua
TDD之Dummy Stub Fake Mock 测试驱动大家都很熟悉了,这两天正好看了一个java的书,对TDD中的一些基本概念进行了复习,具体如下: Dummy An object that is passed around but never used. Typically used to fulfill the parameter list of a method. Stub An object that always returns the same canned response.
I believe the biggest distinction is that a stub you have already written with predetermined behavior. So you would have a class that implements the dependency (abstract class or interface most likely) you are faking for testing purposes and the meth