README.md

March 15, 2026 · View on GitHub

Imposter logo

Mocking library with the perfect balance of Performance and Intuitive API

Build, Test, and Format verification Nuget

🧘Balanced Performance and Developer Experience

Imposter delivers top-tier performance without sacrificing a natural, intuitive API. While being ~10× faster than NSubstitute and up to ~50× faster than Moq in common mocking scenarios, Imposter is not the fastest mocking library available. Instead, it focuses on achieving a balance between performance and API ease of use.

🚀 Quick Start

Add nuget package reference:

dotnet add package Imposter

Pick a target


namespace Application.Domain;

public interface ICalculator
{
    int Add(int a, int b);
}

Use [GenerateImposter] attribute in your tests project, this will generate an imposter

[assembly: GenerateImposter(typeof(Application.Domain.ICalculator))]

Use the generated imposter

using System.Threading.Tasks;
using Imposter.Abstractions;

// c# 14
var imposter = ICalculator.Imposter();

// c# 9 - 13
// var imposter = new ICalculatorImposter();

imposter.Add(Arg<int>.Any(), Arg<int>.Any())
    .Returns(1)
    .Then()
    .Returns(2);

var calculator = imposter.Instance();

calculator.Add(1, 2); // 1
calculator.Add(1, 2); // 2

🛡️ Strongly typed all the way

Loosely typed callbacks can easily cause runtime exceptions. Imposter enforces strong typing across the entire mocking pipeline, eliminating type mismatch errors for good. See more here

🎭 Interfaces and classes

Not limited to interfaces — Imposter can impersonate non-sealed classes and their protected members. See more here

🧬 Full generic support

Generics are fully supported. see more here

🧩 Mock any member

Imposter supports not only methods, but also properties, events and indexers.

🔀 Implicit and Explicit Modes

Choose how unmocked members behave. Implicit mode returns defaults silently — great for prototyping. Explicit mode throws on any call without a setup — ideal for unit tests that must be precise. See more here

🧵 Thread-safe by design

Imposter is built to work reliably in multi-threaded and parallel test environments.

⏱️ Benchmark

Square method is setup to return input * input and ran it for 1, 10, 100, and 1000 iterations. see benchmarks for more details

public interface ICalculator
{
    int Square(int input);
}
MethodIterationMeanAllocated
Moq178,776.14 ns13148 B
NSubstitute11,624.16 ns7664 B
FakeItEasy11,939.11 ns5617 B
Rocks137.91 ns304 B
Imposter1188.72 ns2408 B
Moq101,153,399.52 ns117789 B
NSubstitute1011,919.78 ns27897 B
FakeItEasy109,464.72 ns35727 B
Rocks10627.42 ns1888 B
Imposter101,712.15 ns22424 B
Moq1007,488,213.33 ns1445159 B
NSubstitute100205,099.09 ns222676 B
FakeItEasy100172,337.20 ns732299 B
Rocks10025,495.06 ns17728 B
Imposter10030,005.13 ns222584 B
Moq100098,890,235.56 ns43233637 B
NSubstitute100019,440,858.58 ns2174740 B
FakeItEasy100015,170,287.96 ns46895901 B
Rocks10001,868,905.85 ns176128 B
Imposter10002,256,458.40 ns2224184 B

Benchmark Environment

BenchmarkDotNet v0.15.6, Windows 11 (10.0.26200.6899)
13th Gen Intel Core i9-13900HX 2.20GHz, 1 CPU, 32 logical and 24 physical cores
.NET SDK 10.0.100
[Host]     : .NET 8.0.21 (8.0.21, 8.0.2125.47513), X64 RyuJIT x86-64-v3
DefaultJob : .NET 8.0.21 (8.0.21, 8.0.2125.47513), X64 RyuJIT x86-64-v3
Benchmarks on macOS (Apple M2 Pro)
MethodIterationExecution TimeAllocated Memory
Moq162,199.5 ns12.85 KB
NSubstitute11,688.9 ns8.05 KB
FakeItEasy12,023.3 ns5.68 KB
Rocks146.2 ns0.30 KB
Imposter1250.8 ns2.73 KB
Moq10634,227.3 ns115.07 KB
NSubstitute109,484.3 ns28.46 KB
FakeItEasy109,346.8 ns35.06 KB
Rocks10587.9 ns1.84 KB
Imposter102,419.2 ns25.65 KB
Moq1006,619,086.5 ns1412.43 KB
NSubstitute100224,316.0 ns236.98 KB
FakeItEasy100228,507.4 ns715.71 KB
Rocks10028,261.9 ns17.31 KB
Imposter10036,118.9 ns254.87 KB
Moq100098,252,350.2 ns42221.29 KB
NSubstitute100025,223,566.8 ns2312.93 KB
FakeItEasy100019,298,298.4 ns45797.90 KB
Rocks10002,574,515.3 ns172.00 KB
Imposter10004,011,942.7 ns2547.05 KB

Benchmark Environment

BenchmarkDotNet v0.15.6, macOS Sequoia 15.7.3 (24G419) [Darwin 24.6.0]
Apple M2 Pro, 1 CPU, 10 logical and 10 physical cores
.NET SDK 10.0.101
[Host]     : .NET 10.0.1 (10.0.1, 10.0.125.57005), Arm64 RyuJIT armv8.0-a
DefaultJob : .NET 10.0.1 (10.0.1, 10.0.125.57005), Arm64 RyuJIT armv8.0-a

✨ Feature-Rich

Docs

📜 MIT License

Free to use, modify, and distribute under the MIT License.