Rhino Mocks上的模拟和存根之间有什么区别? [英] What are the differences between mocks and stubs on Rhino Mocks?

查看:61
本文介绍了Rhino Mocks上的模拟和存根之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此还不够玩,通常使用模拟游戏,但是我想知道两者之间的区别以及何时在Rhino Mocks上使用一个或另一个.

更新:

我还在Ayende的书中找到了我的问题的答案单词:

存根和模拟之间的区别

您可以在本文中获得以下术语的实际定义:不是存根".从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.

Update:

I also found the answer to my question in Ayende's words:

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.

解决方案

As per this

... 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.

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上的模拟和存根之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆