我玩得还不够多,通常使用模拟,但我想知道这两者之间有什么区别以及何时在 Rhino Mocks 上使用其中一个.
I haven't play enough with this and usually use mocks, but I wonder what are the differences between this two and when to use one or the other on Rhino Mocks.
更新:
我还在 Ayende's 中找到了我的问题的答案单词:
存根和模拟之间的区别您可以在本文中获得这些术语的实际定义:Mocks Aren't Stubs.我想从 Rhino Mocks 的角度来关注不同之处.
The difference between stubs and mocks You can get the actual definition of the these terms in this article: Mocks Aren't Stubs. I want to focus on the difference from the point of view of Rhino Mocks.
模拟是我们可以设置期望的对象,它将验证期望的操作确实发生了.存根是您用来传递给被测代码的对象.您可以对其设置期望,因此它会以某些方式起作用,但这些期望永远不会得到验证.存根的属性会自动表现得像普通属性一样,您不能对它们设置期望.
A mock is an object that we can set expectations on, and which will verify that the expected actions have indeed occurred. A stub is an object that you use in order to pass to the code under test. You can setup expectations on it, so it would act in certain ways, but those expectations will never be verified. A stub's properties will automatically behave like normal properties, and you can't set expectations on them.
如果您想验证被测代码的行为,您将使用具有适当期望的模拟,并进行验证.如果您只想传递一个可能需要以某种方式执行但不是此测试重点的值,您将使用存根.
If you want to verify the behavior of the code under test, you will use a mock with the appropriate expectation, and verify that. If you want just to pass a value that may need to act in a certain way, but isn't the focus of this test, you will use a stub.
重要提示:存根永远不会导致测试失败.
IMPORTANT: A stub will never cause a test to fail.
推荐答案根据this
... 简单来说,Mock 和 Stub 对象是有区别的并且 RhinoMocks 认识到允许我们编写更好的测试陈述他们的目的.
... Put simply there is a difference between Mock and Stub objects and RhinoMocks recognizes that allowing us to write tests that better state their purpose.
模拟对象用于定义期望,即:在这种情况下,我期望方法 A() 用这样那样的参数调用.模拟记录并验证此类期望.
Mock objects are used to define expectations i.e: In this scenario I expect method A() to be called with such and such parameters. Mocks record and verify such expectations.
另一方面,存根有不同的用途:它们不记录或验证期望,而是允许我们替换"行为,假"对象的状态,以便利用测试场景...
Stubs, on the other hand have a different purpose: they do not record or verify expectations, but rather allow us to "replace" the behavior, state of the "fake"object in order to utilize a test scenario ...
更多推荐
Rhino Mocks 上的 mock 和 stub 有什么区别?
发布评论