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 ...
随机推荐
- At least one object must implement IComparable
中文:必须至少有一个对象实现 IComparable. 序列排序时报这个错误 lstReports.OrderBy(r => new { r.DepartmentName, r.ReportNo ...
- Bluestacks 使用
Bluestack介绍 一款能够在PC模拟Android的好用模拟器 官网:http://www.bluestacks.cn/ 早在2012年就使用上它了,但一直未发现他的许多优点,在使用过其它的两款 ...
- Unity抗锯齿
Unity抗锯齿设置是针对模型,对模型的阴影的锯齿设置无效,不知道我这样的理解是否正确. 遇到的问题 而我是要对灯光照射在模型上产生的阴影进行抗锯齿,暂时还未研究出解决方案,希望知道的朋友告知一声. ...
- java 20 - 8 字节流的文件复制以及汉字在计算机中的存储方式
复制文本文件:把当前目录下的FileIntputStream.java文件里面的内容复制到当前目录的b.txt文件中 分析: 数据源: FileIntputStream.java -- 读取数据 -- ...
- IOS证书/私钥/代码签名/描述文件
1. 相关资源 (1) 钥匙串程序(常用工具->钥匙串),用于创建证书请求.安装证书.导出私钥等 (2) IOS开发中心:https://developer.apple.com/de ...
- 如何替换orcl实例下的四个数据库
1,drop 数据库对应的用户 2,创建新的表空间 新的用户 3,导入新的数据库 imp grid_sysdb/sagis@klmy file=F:\data\addr_interestpoint.d ...
- trac项目管理平台
本文来自百科,由于是非Python开发者,所以仅为了拓宽知识面 1软件介绍 Trac是一个为软件开发项目需要而集成了Wiki和问题跟踪管理系统的应用平台,是一个开源软件应用.Trac以简单的方式建立了 ...
- C++ 排序、查找的应用
// order.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "string.h" #includ ...
- Windows和Linux上用C与Lua交互
Windos2010编译lua的方法: http://blog.csdn.net/appletreesujie/article/details/12065369 Linux编译lua的方法: make ...
- [CareerCup] 9.4 Subsets 子集合
9.4 Write a method to return all subsets of a set. LeetCode上的原题,请参见我之前的博客Subsets 子集合和Subsets II 子集合之 ...