Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 848
chugh97 Avatar asked Mar 29 '10 08:03

chugh97


People also ask

Which is a valid mock type using Rhino?

Mocks supports three basic types of mock objects: Strict Mock. A strict mock requires you to provide alternate implementations for each method/property that is used on the mock. If any methods/properties are used which you have not provided implementations for, an exception will be thrown.


1 Answers

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

like image 107
Sam Holder Avatar answered Oct 06 '22 12:10

Sam Holder