Rhino Mocks is a dynamic mock object framework for the .Net platform. Its purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.


Rhino Mocks is Open Source and released under the BSD license.


Rhino Mocks has a vibrant community, mostly in the mailing list.

Show me the code

As usual, the best way to explain what a library does is to look at the code using it. Here is an example of verifying that when we execute the "forgot my password" scenario, we remembered to call the Save() method properly:

public void When_user_forgot_password_should_save_user()
    var stubUserRepository = MockRepository.GenerateStub<IUserRepository>();
    var stubbedSmsSender = MockRepository.GenerateStub<ISmsSender>();

    var theUser = new User{HashedPassword = "this is not hashed password"};    

    stubUserRepository.Stub(x => x.GetUserByName("ayende")).Return(theUser);

    var controllerUnderTest = new LoginController(stubUserRepository, stubbedSmsSender);


    stubUserRepository.AssertWasCalled( x => x.Save(user));

What is it doing?

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.