How to use Rhino Mocks - documented through tests

Posted on March 12th, 2010 in .NET, Rhino Mocks, TDD, unit testing by Jon Kruger

I wanted to come up with a way to show people how to use Rhino Mocks (other than telling them to read the documentation). What better way to do this than by showing you how it works through a bunch of simple unit tests that document how Rhino Mocks works?

So that’s what I did. You can view the code here, or if you want to download the whole project and run the tests, you can get the whole thing here.

(If you’re interested in Moq, how it compares to Rhino Mocks, and to see Moq documented through tests, check out Steve Horn’s post.)

UPDATE: Fixed the test that was incorrectly showing how to use Expect() and VerifyAllExpectations(). Thanks to Sharon for pointing this out.

8 Responses to 'How to use Rhino Mocks - documented through tests'

Subscribe to comments with RSS or TrackBack to 'How to use Rhino Mocks - documented through tests'.


  1. on March 12th, 2010 at 2:11 pm

    How to use Rhino Mocks - documented through tests…

    You’ve been kicked (a good thing) - Trackback from DotNetKicks.com…


  2. on March 19th, 2010 at 7:42 am

    This is a great resource (and a cool way to present it); I’ve been sharing it with my co-workers. It contains a false-positive test, though–the stub.VerifyAllExpectations test isn’t verifying. I had been thinking of blogging about that particular gotcha, so this was the perfect example to use in my explanation.
    http://www.lostechies.com/blogs/sharoncichelli/archive/2010/03/18/rhino-mocks-examples-with-a-fix.aspx

    Thanks for creating this blog post/test fixture. (Also, NBehave is cool; I hadn’t seen it in action before. It makes your tests especially readable. Nice.)

  3. Bharath said,

    on August 20th, 2010 at 2:26 am

    Good one and well written sample code for Rhino Mocks.

  4. clima said,

    on August 20th, 2010 at 4:03 pm

    Thanks for the example. Finally something I can use as a guide.

  5. Rich said,

    on November 26th, 2010 at 4:13 am

    Excellent guide which really helps a newbie get started using RhinoMocks. One question though, the Should.dll, are these extenstion methods that you have written? Only I would have thought it would be better to have your examples use standard Rhino Mocks syntax.

  6. Jon Kruger said,

    on November 26th, 2010 at 6:30 am

    @Rich,

    The Should library doesn’t replace anything in Rhino.Mocks, it replaces NUnit assertions like Assert.IsTrue. I’m using all of the actual Rhino.Mocks methods in the examples.

    (And no, I didn’t write the Should library)


  7. on June 29th, 2011 at 7:02 am

    Useful Links…

    Up to date rhino Mocks guide…


  8. on December 13th, 2011 at 3:00 pm

    [...] The documentation for RhinoMocks is a little bit cryptic, but covers a lot. They also have a pretty good Quick Reference PDF. http://jonkruger.com/blog/2010/03/12/how-to-use-rhino-mocks-documented-through-tests/ [...]

Post a comment