Project Description
Mockery enables you to write clear, concise unit tests that have injectible dependencies. Mockery removes the redundant code found in these scenarios and enables you to DRY tests that are easy to create, easy to understand and easy to maintain.

What Mockery Is
Mockery supports building out unit tests in a AAA (Arrange/Act/Assert) format for constructor injected objects. It is written to support a 'fluent-style' build up and execution of unit tests using your IoC container of choice to compose the object at test time.

What Mockery Isn't
  • It is not a mocking tool... Mockery is built on top of RhinoMocks
  • It is not a unit testing tool... Mockery does not dictate your unit testing tool, you can use NUnit, MBUnit, xUnit, msunit or any other tool with it.
  • It is not an IoC container... You can build tests that rely on your IoC of choice by virtue of the CommonServiceLocator

Check out the documentation for more details on what mockery is and how to use it.

Project Needs
As Mockery is a new project, there are a number of needs where people can get involved. Please check out the Community Involvement Page for a current list of needs and wants.

Code Sample

Mockery has multiple components that are accessed in the following order:
Step 0 - Create test data
const int accountNumber = 42;
const int balance = 4;
var actualOutput = 0; 


Step 1 - Declare
Mockery starts with a declaration that makes the class under test distinctly declared:
InjectedTest.Target<MyClass>()

This creates the core Mockery object and sets the stage for the test...
Step 2 - Arrange
Arrange the dependencies of the object by setting up the mocks and their expectations
  .Arrange( a => a.AddDynamicMock<MyDependency>()
                  .ExpectOn<MyDependency>( e => Expect.Call( e.Process(accountNumber)).Return(balance )))

Step 3 - Act
The default .Act signature hands you an instance of the class under test. Multiple .Act statements may be strung together, but in most scenarios one should suffice.
    .Act( a => actualOutput = a.GetBalance(accountNumber ) )

Step 4 - Assert
And finally, we'll assert on any values obtained in the .Act phase with...
    .Assert( Assert.That(actualOutput, Is.EqualTo(balance)));

Last edited Jan 1, 2010 at 2:38 PM by sdhebert, version 24