stubs 和 mocks区别

本文探讨了Mock与Stub在软件测试中的不同角色。Mock用于验证被测代码的行为是否符合预期,而Stub则主要用于向被测系统提供固定的行为或响应。文章还强调了在使用RhinoMocks框架时,Mock会验证预期行为是否发生,而Stub永远不会导致测试失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 

http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx

转载于:https://www.cnblogs.com/dbasys/archive/2012/11/30/2796224.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值