Auto-Mocking with FakeItEasy and AutoFixture
14 December 2011
AutoFixture can become an auto-mocking container using Moq (described here) and Rhino Mocks (described here).
In addition to the above auto-mocking features it is now possible to use FakeItEasy.
To install AutoFixture with Auto Mocking using FakeItEasy, run the following command in the Package Manager Console:
To use it, add an AutoFakeItEasyCustomization to the Fixture instance:
Here is a typical usage inside a test method which will automatically create mocked instances using FakeItEasy:
To explicitly use FakeItEasy inside a test you need to Freeze it first:
The above example can be made even more elegant by using AutoData theories:
Update (2014/02/28): It is also possible to use the
[Frozen] attribute on the
IInterface directly, as Mark Seemann commented here.
Below is the code for the AutoFakeItEasyDataAttribute class:
An automatically published release created from the latest successful build can also be downloaded from here.