

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I haven't play enough with this and usually use mocks, but I wonder what are the differences between this two and when to use one or the other on Rhino Mocks.


I also found the answer to my question in Ayende's words:

The difference between stubs and mocks

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.


IMPORTANT: A stub will never cause a test to fail.

share|improve this question
possible duplicate of What's the difference between faking, mocking, and stubbing? – nawfal Jul 23 '14 at 18:02
up vote 109 down vote accepted

As per this

... Put simply there is a difference between Mock and Stub objects and RhinoMocks recognizes that allowing us to write tests that better state their purpose.

Mock objects are used to define expectations i.e: In this scenario I expect method A() to be called with such and such parameters. Mocks record and verify such expectations.

Stubs, on the other hand have a different purpose: they do not record or verify expectations, but rather allow us to “replace” the behavior, state of the “fake”object in order to utilize a test scenario ...

share|improve this answer

Difference between Mock and stub: with stub, you fix the input of your unit test: so your unit test doesn't make assertion on stub and Stub by rewriting the implementation of some method fix the behavior of fake object. with Mock, you fix the ouput of your unit test: so your unit test make an expectation on your Mocking object by checking internal interaction in your mock object.

share|improve this answer
You seem to be saying that your test should "check" the output of a mock. If that's what you are saying, you are incorrect. A mock is not supposed to be tested; it's there so you can test other code. Or does your last sentence mean something else? – Andrew Barber Nov 7 '12 at 20:06
Hi Andrew, as i have written With Mock you fix the output of your test so you won't test it.Otherwise i have written that Mock allow you to check interaction (expectation behavior...;-) – Hassan Boutougha Nov 9 '12 at 13:37
OK, that makes more sense. Thanks for the clarification! – Andrew Barber Nov 9 '12 at 17:18
>doesn't make assertion on stub Why in many assertion libraries still exists methods aka should have been called with to assert stub parameters. – hellboy Dec 7 '15 at 10:56

In case of Moq framework - setup method is STUB where as Verify method is Mock

share|improve this answer

One thing that I noticed too is that when I use MockRepository.GenerateMock, I need to explicitly set expectations on a specific method call to intercept that call. With stubs, it seems to automatically intercept any method as long as it is virtual.

share|improve this answer

Your Answer


