MiniMock

Minimalistic approach to mocking in .NET

View on GitHub

Getting started

Installation and First Use

Reference the NuGet package in your test project:

dotnet add package MiniMock

As code:

[Fact]
[Mock<IMyRepository>] // Specify which interface to mock
public void MyTest() {
    var mockRepo = Mock.IMyRepository(// Create a new instance of the mock using the mock factory
        config => config // Configure the mock using the config parameter
            .CreateCustomerAsync(return: Guid.NewGuid()) // Specify how the relevant members should behave
        );
    var sut = new CustomerMaintenance(mockRepo); // Use the mock in your test as you see fit
    
    sut.Create(customerDTO, cancellationToken);
}

Quality of Life

MiniMock is extremely strict but fair, requiring you to specify all features you want to mock but giving you fair warnings if you don’t. This is by design to make sure you are aware of what you are mocking and not introduce unexpected behaviour.

img.png

All mockable members are available through a fluent interface with IntelliSense, type safety, and documentation.

img_2.png

All code required to run MiniMock is source generated within your test project and has no runtime dependencies. You can inspect, step into, and debug the generated code which also allows for security and vulnerability scanning of the code.