zoukankan      html  css  js  c++  java
  • Rhino Mock

    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,之类时 是一样的。

  • 相关阅读:
    Python httpServer服务器(初级)
    分布式服务管理zookeeper的java api
    基于netty的异步http请求
    for之Python vs C#
    表单验证
    contact表单错误解决记录
    表单
    Django后台管理界面
    正则表达式替换和不包含指定字符串
    Django模型-数据库操作
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/4076703.html
Copyright © 2011-2022 走看看