I'm using Rhino Mocks in my unit test.
I would like to know the difference between STUBS and MOCKS (mocks.Stub<T>()
and mocks.StrictMock<T>()
).
A stub is simply an alternate implementation. A mock, however, is more than that. In Rhino.Mocks, you used the .Stub() and .Expect() extension methods to generate your stubs and mocks directly off your mock object. Moq, on the other hand, uses the .Setup() method on the wrapper object to create both.
Rhino Mocks will generate fake objects to replace the dependencies that you have, and then allow you to tell them, at runtime, how to behave. This functionality is very powerful, and it means that you can tell your fake objects, for each test, how to behave.
With Rhino.Mocks, the MockRepository returns to you an instance of the type you're mocking and you apply the mock operators ( .Stub (), .Expect (), .VerifyAllExpectations (), etc) directly to that mocked object. Moq, on the other hand, creates a wrapper object that contains a reference to the mocked type.
Rhino Mocks will generate fake objects to replace the dependencies that you have, and then allow you to tell them, at runtime, how to behave. This functionality is very powerful, and it means that you can tell your fake objects, for each test, how to behave. As usual, the best way to explain what a library does is to look at the code using it.
I think it had been asked before.
It is generally the same with the following differences:
Stub
, Expect
nor AssertWasCalled
on properties. This behaviour can also be configured on a normal Mock too. But for stubs it is the default.Since Rhino changed to AAA syntax, it is discouraged to use Strict Mocks, since they make test code very hard to maintain.
Similar questions:
I can't find the information about the Rhino implementation, so I don't mark this question as duplicate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With