使用的规则。
All I need to do is abide by three rules:
一。主要思想。
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.
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,之类时 是一样的。