software solutions / project leadership / agile coaching and training

How to use Rhino Mocks – documented through tests

Posted on March 12, 2010

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.


  1. How to use Rhino Mocks – documented through tests…

    You’ve been kicked (a good thing) – Trackback from… — March 12, 2010 @ 2:11 pm

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

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

    Sharon Cichelli — March 19, 2010 @ 7:42 am

  3. Good one and well written sample code for Rhino Mocks.

    Bharath — August 20, 2010 @ 2:26 am

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

    clima — August 20, 2010 @ 4:03 pm

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

    Rich — November 26, 2010 @ 4:13 am

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

    Jon Kruger — November 26, 2010 @ 6:30 am

  7. Useful Links…

    Up to date rhino Mocks guide…

    Confluence: Development — June 29, 2011 @ 7:02 am

  8. [...] The documentation for RhinoMocks is a little bit cryptic, but covers a lot. They also have a pretty good Quick Reference PDF. [...]

    Introduction to Rhino Mocks | SoftArtisans, Blogged Introduction to Rhino Mocks | The Cathedral and the Bizarre — December 13, 2011 @ 3:00 pm

  9. Jon, thanks, great article!

    Object — April 5, 2012 @ 1:29 pm

  10. Thank you, I found them very useful

    Michael Coxeter — April 15, 2012 @ 5:18 am

  11. Right on spot. Tried to understand it before but couldn’t. This style on explanation is great on very easy to get. Thanks Jon.

    Pankaj — May 24, 2013 @ 2:34 pm

  12. Nice Article.
    thank you Jon.

    Ajay — August 27, 2013 @ 7:51 am

  13. Is this uptodate? I am confused. for example, this article uses “MockRepository.GenerateStub” whereas I do not have “GenerateStub” available. I have however “Mock” which works fine.

    So, I replace the call




    Thank you

    dino — May 18, 2017 @ 3:22 pm

Leave a comment

I have over 15 years of software development experience on several different platforms (.NET, Ruby, JavaScript, SQL Server, and more). I recognize that software is expensive, so I'm always trying to find ways to speed up the software development process, but at the same time remembering that high quality is essential to building software that stands the test of time.
I have experience leading and architecting large Agile software projects and coordinating all aspects of a project's lifecycle. Whether you're looking for technical expertise or someone to lead all aspects of an Agile project, I have proven experience from multiple projects in different environments that can help make your project a success.
Every team and every situation is different, and I believe that processes and tools should be applied with common sense. I've spent the last 10+ years working on projects using Agile and Lean concepts in many different environments, both in leadership roles and as a practitioner doing the work. I can help you develop a process that works best in your organization, not just apply a prescriptive process.
Have any questions? Contact me for more information.
Ditching the Office - How an everyday corporate development team turned into a remote working team
From Stir Trek 2018
From Stir Trek 2017, cbus.js 2017
Iteration Management - Your Key to Predictable Delivery
From Stir Trek 2016 and QA or the Highway 2015
From CodeMash 2016, QA or the Highway 2014, Stir Trek 2012
The Business of You: 10 Steps For Running Your Career Like a Business
From CodeMash 2015, Stir Trek 2014, CONDG 2012
From Stir Trek 2013, DogFoodCon 2013
(presented with Brandon Childers, Chris Hoover, Laurel Odronic, and Lan Bloch from IGS Energy) from Path to Agility 2012
From CodeMash 2012 and 2013
(presented with Paul Bahler and Kevin Chivington from IGS Energy)
From CodeMash 2011
An idea of how to make JavaScript testable, presented at Stir Trek 2011. The world of JavaScript frameworks has changed greatly since then, but I still agree with the concepts.
A description of how test-driven development works along with some hands-on examples.
From CodeMash 2010
From CodeMash 2010