Mockito-like annotations for .NET
See MovieFinderTest for a usage example
Visual Studio Package Manager Console:
Install-Package MockAttributes
Nuget:
nuget install MockAttributes
dotnet core:
dotnet add package MockAttributes
By default, MockAttributes
assumes you're using Moq
, so that it can extract the proxy object generated by Castle DynamicProxy
and inject it into the class-under-test.
If you're using hand-rolled mocks or your mocking library doesn't wrap a class around the proxy object in the way that Moq
does, you can pass an instance of DefaultProxyObjectExtractor
into MockInjector.Inject
.
For any other cases, you can implement IProxyObjectExtractor
.
- inject mocks into test class
- inject mocked objects into class-under-test (for
Moq
initially, although could be made more general) - stand-up class-under-test with mocked objects
- suppress CS0649 ("Field is never assigned to, and will always have its default value null")
- support properties
- unit tests
- handle classes with multiple dependencies of the same type
- fallback to property injection if no suitable constructors are found