1. mock interfaces, delegates and classes, including those with parameterized constructors.
  2. set expectations on the called methods by using strongly typed mocks instead of strings.
  3. lends itself easily to refactoring & leaning on the compiler.
  4. allows a wide range of expectations to be set on a mock object or several mock objects.
  5. 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)
  6. 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:

  1. Use the static MockRepository.GenerateMock method.  Don’t use an instance of a MockRepository, and don’t use the GenerateStub method.
  2. 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.
  3. 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的更多相关文章

  1. C#单元测试面面观

    标题有点标题党,但相信各位看完这篇文章一定会所收获,如果之前没有接触过单元测试或了解不深通过本文都能对单元测试有个全新认识.本文的特点是不脱离实际,所测试的代码都是常见的模式. 写完这篇文章后,我看了 ...

  2. .Net架构必备工具列表

    ★微软MSDN:每个开发人员现在应该下载的十种必备工具 点此进入 ★网友总结.Net架构必备工具列表 Visual Studio 这个似乎是不言而喻的,只是从严谨的角度,也列在这.实际上,现在也有一个 ...

  3. 我的TDD实践---UnitTest单元测试

    我的TDD实践---UnitTest单元测试 “我的TDD实践”系列之UnitTest单元测试 写在前面: 我的TDD实践这几篇文章主要是围绕测试驱动开发所展开的,其中涵盖了一小部分测试理论,更多的则 ...

  4. 新.Net架构必备工具列表

    N多年前微软官网曾发了.Net下必备的十种工具,N多年过去了,世异时移,很多东西都已经变化了,那个列表也似乎陈旧了.而且,该文也只是对十种工具独立的介绍,显得有些罗列的感觉,是不是每个工具都是同等重要 ...

  5. C# Rhino Mocks

    Mock和Stub的区别: 1,Stub是一个在你的测试代码中需要用到的object,你可以为它设置expectations,然后它就会按其运行,但是这些expectations不会被核对. 2,Mo ...

  6. TDD学习笔记【六】一Unit Test - Stub, Mock, Fake 简介

    这篇文章简介一下,如何通过 mock framework,来辅助我们更便利地模拟目标对象的依赖对象,而不必手工敲堆只为了这次测试而存在的辅助类型. 而模拟目标对象的部分,常见的有 stub objec ...

  7. [转]TDD之Dummy Stub Fake Mock

    TDD之Dummy Stub Fake Mock 测试驱动大家都很熟悉了,这两天正好看了一个java的书,对TDD中的一些基本概念进行了复习,具体如下: Dummy An object that is ...

  8. 使用模拟对象(Mock Object)技术进行测试驱动开发

    敏捷开发 敏捷软件开发又称敏捷开发,是一种从上世纪 90 年代开始引起开发人员注意的新型软件开发方法.和传统瀑布式开发方法对比,敏捷开发强调的是在几周或者几个月很短的时间周期,完成相对较小功能,并交付 ...

  9. Mock Framework

    Typemock Isolator; Rhino Mocks; NMock; MS Fakes(has not same mechanism with NMock) Mock is usually u ...

随机推荐

  1. [转]JavaScript实现 页面滚动图片加载

    本文转自:http://www.cnblogs.com/Darren_code/archive/2011/07/21/LoadImage.html 又到了这个月的博客时间了,原计划是打算在这个月做一个 ...

  2. HTML5秘籍读书笔记

    1:基本雏形 <html><head> <meta charset="UTF-8"> <title></title>&l ...

  3. fontAwesome代替网页icon小图标

    引言 奥森图标(Font Awesome)提供丰富的矢量字体图标—通过CSS可以任意控制所有图标的大小 ,颜色,阴影. 网页小图标到处可见,如果一个网页都是干巴巴的文字和图片,而没有小图标,会显得非常 ...

  4. [3D跑酷] DataManager

    DataManager管理游戏中数据,当然这个类中大部分的属性和方法都是Public 函数列表

  5. Android Studio 三种添加插件的方式,androidstudio

    前几篇blog我们介绍了如何安装和配置Android Studio,这篇Blog我们来聊聊如何给Android Studio添加插件,添加插件的路径有三种,我把他们分类如下: 点击设置小按钮 点击[P ...

  6. 关联:objc_getAssociatedObject和objc_setAssociatedObject使用

    为UIButton的category添加属性 UIButton+subTitle.h #import <UIKit/UIKit.h> #import <objc/runtime.h& ...

  7. isScroll代码

    html: <div class="wrap"> <div class="content"> //内容-必须为第一个子元素 </d ...

  8. workerman & swoole

    Socket 开发 workerman swoole swoole与phpdaemon/reactphp/workerman等纯PHP网络库的差异

  9. MySQL基础 - 内置函数

    Concat() 用于连接字段,一般DBMS使用+或者||. ex: 注意:上图中新检索出来的列名为'CONCAT(id, '->', name)'(实际上没有列名),这样虽然不影响在MySQL ...

  10. win7桌面移到其他盘

    打开"计算机",点"用户"--"Administrator"点进去,或者,打开我的文档,然后右键点"桌面""属 ...