Rhino Mocks - Difference between GenerateStub<T> & GenerateMock<T> [closed]

六眼飞鱼酱① 提交于 2019-12-17 10:25:36

问题


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

Where should one use Stub over Mock method or otherwise?


回答1:


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.

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.

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

Also this question might be useful as might this one



来源:https://stackoverflow.com/questions/2536551/rhino-mocks-difference-between-generatestubt-generatemockt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!