Rhino Mock
- mock interfaces, delegates and classes, including those with parameterized constructors.
- set expectations on the called methods by using strongly typed mocks instead of strings.
- lends itself easily to refactoring & leaning on the compiler.
- allows a wide range of expectations to be set on a mock object or several mock objects.
- Attention: Rhino Mocks can only mock interfaces, delegates and virtual methods of classes! (Although it is possible to get work around existing code and easily apply Rhino Mocks, see Example of testing an abstract class)
- Rhino Mocks now supports "Recursive mocking" (as of revision 1683). Special guidance (see here) should be followed when using this functionality, however.
使用的规则。
All I need to do is abide by three rules:
- Use the static MockRepository.GenerateMock method. Don’t use an instance of a MockRepository, and don’t use the GenerateStub method.
- If the mocked instance method returns a value, use the Stub method to set up a result for that value. This is an indirect input.
- If the mocked instance method does not return a value (void), use the AssertWasCalled/AssertWasNotCalled methods. This is an indirect output.
一。主要思想。
1。 Record/Replay 方式,在record mode set up expectation . in replay mode verify .(列出预期的方法,调用,验证是否被调用,调用顺序。)
2. Arrange/Act/Assert方式,(类似于传统的nunit方法,准备数据,执行,假设结果)
Rhino Mocks currently support the creation of the following types of mock objects.
- Mock Objects - Strict replay semantics. Created by calling StrictMock()
- Dynamic Mock - Loose replay semantics. Created by calling DynamicMock()
- Partial Mock - Mock only requested methods. Created by calling PartialMock()
Strict replay semantics: Only the methods that were explicitly recorded are accepted as valid. This means that any call that is not expected would cause an exception and fail the test. All the expected methods must be called if the object is to pass verification.
严谨重播语义:只有显示记录的方法才是有效的,对任何未预期的方法进行调用都会导致异常。所有预期的方法都必须被调用,对象才能通过验证。
Loose
replay semantics: All method calls during the replay state are
accepted. If there is no special handling setup for a given method, a
null or zero is returned. All of the expected methods must be called for
the object to pass verification.
松散重播语义:所有的方法都可以调用,未预期的调用会返回0 or null 所有的预期方法必须被调用,对象才能通过验证。
Mocking
only requested methods: This is available for classes only. It
basically means that any non abstract method call will use the original
method (no mocking) instead of relying on Rhino Mocks' expectations. You
can selectively decide which methods should be mocked.
仅模拟请求的方法:只适用于类。
DynamicMock 用于验证部分方法,StrictMock用于整个接口验证。PartialMock 可以用于测试类,抽象类的部分方法,尤求是模板方法的测试。
DynamicMock和StrictMock的区别仅限于上面提到的,而实际使用时,效应各个方法入 record,之类时 是一样的。
Rhino Mock的更多相关文章
- C#单元测试面面观
标题有点标题党,但相信各位看完这篇文章一定会所收获,如果之前没有接触过单元测试或了解不深通过本文都能对单元测试有个全新认识.本文的特点是不脱离实际,所测试的代码都是常见的模式. 写完这篇文章后,我看了 ...
- .Net架构必备工具列表
★微软MSDN:每个开发人员现在应该下载的十种必备工具 点此进入 ★网友总结.Net架构必备工具列表 Visual Studio 这个似乎是不言而喻的,只是从严谨的角度,也列在这.实际上,现在也有一个 ...
- 我的TDD实践---UnitTest单元测试
我的TDD实践---UnitTest单元测试 “我的TDD实践”系列之UnitTest单元测试 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则 ...
- 新.Net架构必备工具列表
N多年前微软官网曾发了.Net下必备的十种工具,N多年过去了,世异时移,很多东西都已经变化了,那个列表也似乎陈旧了.而且,该文也只是对十种工具独立的介绍,显得有些罗列的感觉,是不是每个工具都是同等重要 ...
- C# Rhino Mocks
Mock和Stub的区别: 1,Stub是一个在你的测试代码中需要用到的object,你可以为它设置expectations,然后它就会按其运行,但是这些expectations不会被核对. 2,Mo ...
- TDD学习笔记【六】一Unit Test - Stub, Mock, Fake 简介
这篇文章简介一下,如何通过 mock framework,来辅助我们更便利地模拟目标对象的依赖对象,而不必手工敲堆只为了这次测试而存在的辅助类型. 而模拟目标对象的部分,常见的有 stub objec ...
- [转]TDD之Dummy Stub Fake Mock
TDD之Dummy Stub Fake Mock 测试驱动大家都很熟悉了,这两天正好看了一个java的书,对TDD中的一些基本概念进行了复习,具体如下: Dummy An object that is ...
- 使用模拟对象(Mock Object)技术进行测试驱动开发
敏捷开发 敏捷软件开发又称敏捷开发,是一种从上世纪 90 年代开始引起开发人员注意的新型软件开发方法.和传统瀑布式开发方法对比,敏捷开发强调的是在几周或者几个月很短的时间周期,完成相对较小功能,并交付 ...
- Mock Framework
Typemock Isolator; Rhino Mocks; NMock; MS Fakes(has not same mechanism with NMock) Mock is usually u ...
随机推荐
- Hadoop Shell命令字典(可收藏)
可以带着下面问题来阅读: 1.chmod与chown的区别是什麽?2.cat将路径指定文件的内容输出到哪里?3.cp能否是不同之间复制?4.hdfs如何查看文件大小?5.hdfs如何合并文件?6.如何 ...
- 如何判断两个String是否是Anagrams_java实现
Anagrams:是颠倒字母顺序的字符串 本文提供三个方法,分别分析时间空间复杂度 方法一:暴力遍历 时间复杂度:O(n^2) 方法二:基于排序算法,Sorting的时间复杂度是O(n*log(n)) ...
- ZBrush中的Clip剪切笔刷怎么快速运用
Clip剪切笔刷可以对模型网格进行剪切操作,也可以叫做剪切笔刷.接下来看一下Clip切割笔刷在ZBrush中是如何使用的. 查看更多内容请直接前往:http://www.zbrushcn.com/ji ...
- AC日记——产生数 codevs 1009 (弗洛伊德)(组合数学)
1009 产生数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descriptio ...
- 观察器observes与对象初始化
Demo.Person2 = Ember.Object.extend({ init: function() { alert('lljsd'); this.set('salutation', " ...
- 安卓版微信内置浏览器,<a href="tel:电话号码"></a> 这个链接失效,不能跳到拨号界面?
https://segmentfault.com/q/1010000000318831 在URL最后面加“ #mp.weixin.qq.com ”,应该加其他qq.com的二级域名都行,估计是微信的安 ...
- 021医疗项目-模块二:药品目录的导入导出-介绍poi类
我们使用的是.10版本 Apache POI - the Java API for Microsoft Documents,Apache POI 是用Java编写的免费开源的跨平台的 Java API ...
- 【C#】ContextMenuStrip 右键菜单颜色设置
有些时候自己想要修改ContexMenuStrip右键菜单的一些背景色之类的,该如何实现呢? 首先: ContextMenuStrip _context = new ContextMenuStrip( ...
- java中从1970-1-1到当前时间之间的毫秒数转换为oracle date
java中System.currentTimeMillis()取到的是从1970-01-01 00:00:00.000到当前时间的毫秒数,一个long类型的值. 现在oracle数据库中某表中存取的是 ...
- 供应商和管理员查看供应商地址簿信息SQL
--管理员查看地址簿 SELECT hps.party_site_id, hps.party_site_name AS address_name, 'CURRENT' AS status, hzl.a ...