Rhino Mocks is a very useful and very advanced tool for decoupling and Inversion of Control (IOC).

Rhino Mocks allows the developer to decouple (almost ?) any object from the surrounding object-“world” if the dependencies are accessed through an interface, and provided that alternative mocked dependencies can the injected instead.

It allows quite easily to setup stub functionality, i.e. methods/properties which return a specific result. The main functionality, though, is the mocking of objects. It allows setting up expectations as to which methods are called with specific param-values and how many times, as well as quite elaborate ways of manipulating/checking the passed in params to return a specific result. With the latest versions it’s even possible with very little and quite easily readable code to check event subscription, raise events on the mocked objects and check that the UUT (unit-under-test) raises specific events.

To a large extent Rhino Mocks allows use of the AAA-approach (Arrange, Act, Assert), meaning division into 3 stages, the first being arranging the environment – setting up dependencies and the UUT. The second being actually acting on the UUT, e.g. invoking specific methods etc., and the third being asserting that the results are as expected, e.g. testing variable values, testing that specific events were raised / not raised etc.

Rhino Mocks works well with NUnit 2.5 – we use the combination to test units written for .NET Framework 2.0+ (primarily 3.5). Rhino Mocks 3.6 support .NET 2.0 and 3.5.