NimbleMock 1.0.0

dotnet add package NimbleMock --version 1.0.0
                    
NuGet\Install-Package NimbleMock -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NimbleMock" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NimbleMock" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NimbleMock" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NimbleMock --version 1.0.0
                    
#r "nuget: NimbleMock, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NimbleMock@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NimbleMock&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NimbleMock&version=1.0.0
                    
Install as a Cake Tool

NimbleMock

Zero-allocation, source-generated C# mocking library for exceptional developer experience.

NuGet License: MIT GitHub

Why NimbleMock?

34x faster than Moq, 7x faster than NSubstitute in mock creation. 67% less memory allocation.

// Before (Moq) - 48,812ns, 10.37 KB
var mock = new Mock<IUserRepository>();
mock.Setup(x => x.GetById(1)).Returns(user);
mock.Setup(x => x.SaveAsync(It.IsAny<User>())).ReturnsAsync(true);
var repo = mock.Object;

// After (NimbleMock) - 1,415ns, 3.45 KB
var mock = Mock.Of<IUserRepository>()
    .Setup(x => x.GetById(1), user)
    .SetupAsync(x => x.SaveAsync(default!), true)
    .Build();

Key Features

  • Stack-allocated builders with arrays - zero GC pressure
  • Source generators create compile-time proxies (no Castle.DynamicProxy)
  • Fluent API with intelligent type inference
  • First-class async support (Task<T>, ValueTask<T>)
  • Partial mocks for large interfaces
  • Roslyn analyzers detect unverified calls at compile-time
  • No telemetry (looking at you, Moq)

Installation

dotnet add package NimbleMock

Quick Start

using NimbleMock;
using Xunit;

public interface IUserRepository
{
    User GetById(int id);
    Task<bool> SaveAsync(User user);
}

public class UserServiceTests
{
    [Fact]
    public void GetUser_ReturnsFromRepository()
    {
        // Arrange
        var expectedUser = new User { Id = 1, Name = "Alice" };
        var mock = Mock.Of<IUserRepository>()
            .Setup(x => x.GetById(1), expectedUser)
            .Build();

        var service = new UserService(mock.Object);

        // Act
        var result = service.GetUser(1);

        // Assert
        Assert.Equal(expectedUser, result);
        mock.Verify(x => x.GetById(1)).Once();
    }
}

Performance Comparison

Operation Moq NSubstitute NimbleMock
Setup 48,812 ns 9,937 ns 1,415 ns
Verification 1,795 ns 2,163 ns 585 ns
Memory (Setup) 10.37 KB 12.36 KB 3.45 KB
Memory (Verify) 2.12 KB 2.82 KB 0.53 KB

Benchmarks: .NET 8.0.22, x64, RyuJIT AVX2, Windows 11

Documentation

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests.

License

MIT © 2025

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 187 12/13/2025