Imposter 0.1.4
dotnet add package Imposter --version 0.1.4
NuGet\Install-Package Imposter -Version 0.1.4
<PackageReference Include="Imposter" Version="0.1.4" />
<PackageVersion Include="Imposter" Version="0.1.4" />
<PackageReference Include="Imposter" />
paket add Imposter --version 0.1.4
#r "nuget: Imposter, 0.1.4"
#:package Imposter@0.1.4
#addin nuget:?package=Imposter&version=0.1.4
#tool nuget:?package=Imposter&version=0.1.4
<p align="center"> <img src="docs/imposter_logo.png" alt="Imposter logo" width="140" /> </p>
<p align="center"> The Fastest and Most Memory-Efficient Mocking Library </p>
Visit the Docs for more information
🚀 Quick Start
Add nuget package reference:
dotnet add package Imposter
Pick an interface or non-sealed class that you would like to generate an imposter for.
Say we have a below interface
namespace Application.Domain;
public interface ICalculator
{
int Add(int a, int b);
}
Use [GenerateImposter] attribute in your tests project, this will generate an imoster
[assembly: GenerateImposter(typeof(Application.Domain.ICalculator))]
Then use can use the generated imposter in your tests
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
Learn more: https://themidnightgospel.github.io/Imposter/
✨ Feature-Rich
- Method Impersonation
- Property Impersonation
- Indexer Impersonation
- Event Impersonation
- Class Impersonation
- Generics
- Implicit & Explicit Modes
- Use Base implementation
- Async Support
- Protected members Impersonation
⏱️ Benchmark
We benchmarked the simple method-impersonation scenario: we set up a Square method to return input * input and ran it for 1, 10, 100, and 1000 iterations.
public interface ICalculator
{
int Square(int input);
}
Mean execution time
| Method | Iteration | Mean |
|---|---|---|
| Moq | 1 | 69,346.1 ns |
| NSubstitute | 1 | 1,976.2 ns |
| Imposter | 1 | 194.3 ns |
| Moq | 10 | 686,282.9 ns |
| NSubstitute | 10 | 11,201.6 ns |
| Imposter | 10 | 1,896.7 ns |
| Moq | 100 | 6,804,897.3 ns |
| NSubstitute | 100 | 335,390.6 ns |
| Imposter | 100 | 34,011.7 ns |
| Moq | 1000 | 99,710,929.5 ns |
| NSubstitute | 1000 | 26,986,939.0 ns |
| Imposter | 1000 | 2,452,970.7 ns |
Allocated Memory
| Method | Iteration | Allocated |
|---|---|---|
| Moq | 1 | 13.05 KB |
| NSubstitute | 1 | 7.84 KB |
| Imposter | 1 | 2.4 KB |
| Moq | 10 | 115.73 KB |
| NSubstitute | 10 | 29.29 KB |
| Imposter | 10 | 22.37 KB |
| Moq | 100 | 1416.91 KB |
| NSubstitute | 100 | 247.26 KB |
| Imposter | 100 | 222.05 KB |
| Moq | 1000 | 42275.19 KB |
| NSubstitute | 1000 | 2420.82 KB |
| Imposter | 1000 | 2218.93 KB |
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
See other benchmarks benchmark
Docs
Docs: https://themidnightgospel.github.io/Imposter/
License
Licensed under the MIT License. See LICENSE.txt for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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 |
|---|---|---|
| 0.1.4 | 451 | 11/24/2025 |
| 0.1.3 | 233 | 11/24/2025 |
| 0.1.2 | 243 | 11/22/2025 |
| 0.1.1 | 220 | 11/22/2025 |
| 0.1.0 | 396 | 11/17/2025 |
| 0.0.24 | 343 | 11/17/2025 |
| 0.0.23 | 169 | 11/15/2025 |
| 0.0.22 | 175 | 11/15/2025 |
| 0.0.21 | 181 | 11/15/2025 |
| 0.0.20 | 181 | 11/15/2025 |
| 0.0.19 | 180 | 11/15/2025 |
| 0.0.18 | 187 | 11/15/2025 |
| 0.0.13 | 223 | 11/14/2025 |
Fix ignored “putinsamenamespace” flag for targets in global namespace