SpecsFor and mocking


For a quick intro to creating mock objects with SpecsFor, check out How do I set up a mock object?

SpecsFor aims to keep the uninteresting parts of mocking out of your specs. SpecsFor's auto-mocking container will automatically create mock objects for any of your interface or abstract dependencies. It also tracks these mock objects for you, which is one less thing you have to worry about keeping up with in your specs.

To get an instance of a mock object, just call the GetMockFor method. You'll receive the existing instance of T if a mock for type T has already been created, either because of a previous call to GetMockFor or because your SUT required a mock of T for its constructor. If a mock of T doesn't exist already, one will be created for you.

For more information about how to configure mocks, check out the Moq quickstart.