Rhino Mocks - GenerateStub<T> 之间的区别&GenerateMock<T> [英] Rhino Mocks - Difference between GenerateStub<T> & GenerateMock<T>

查看:44
本文介绍了Rhino Mocks - GenerateStub<T> 之间的区别&GenerateMock<T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何Rhino 专家能否通过在MockRepository 类(Rhino Mocks 框架)上给出上述方法之间差异的合适示例来解释我.

Can any of the Rhino experts explain me by giving a suitable example of the difference between the above methods on the MockRepository class (Rhino Mocks framework).

应该在哪里使用 Stub 而不是 Mock 方法?

Where should one use Stub over Mock method or otherwise?

推荐答案

当你要验证对象上发生了什么事情时,你应该使用模拟,比如调用了一个方法.当您只想让测试中涉及的对象返回一个值但它不是您正在测试的东西时,您应该使用存根.没有满足期望的存根永远不会通过测试.

you should use a mock when you are going to verify that something happened on the object, like a method was called. You should use a stub when you just want the object to be involved in the test to return a value but it is not the thing you are testing. A stub which does not have a expectation fulfilled can never fail a test.

我认为一般规则应该是在测试中你应该只有一个模拟对象,但可能有几个存根为模拟对象提供信息.我相信测试中超过 1 个模拟是代码异味.

I think the general rule should be that you should only ever have a single mock object in a test, but may have several stubs which provide information to the mock object. I believe that more than 1 mock in a test is a code smell.

虽然不是 Rhino 示例 Martin Fowler 对差异进行了描述

Although not a Rhino example Martin Fowler has a description of the difference

另外这个问题可能和这个

这篇关于Rhino Mocks - GenerateStub<T> 之间的区别&GenerateMock<T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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