Mockolate is a modern, strongly-typed, AOT-compatible mocking library for .NET, powered by source generators. It enables fast, compile-time validated mocking with .NET Standard 2.0, .NET 8, .NET 10 and .NET Framework 4.8.
- Source generator-based: No runtime proxy generation.
- Fast: Direct dispatch with no reflection or dynamic proxies.
- Strongly-typed: Compile-time safety and IntelliSense support.
- AOT compatible: Works with Native AOT and trimming.
- Modern C#: First-class support for ref structs, static interface members, and current language features.
| Reflection-based mocks (Moq, NSubstitute, …) | Mockolate | |
|---|---|---|
| AOT / trimming | not supported | supported |
| Validation | runtime exceptions | analyzers + compile errors |
| Setup API | Expression<Func<…>> trees |
regular method calls |
| Hot path | dynamic-proxy dispatch | direct dispatch |
For side-by-side setup, usage, and verification syntax against Moq, NSubstitute, and FakeItEasy, see the full code comparison; for performance, see the benchmarks.
Already on Moq or NSubstitute? The companion package Mockolate.Migration
ships analyzers and code fixers that translate common Moq and NSubstitute patterns to Mockolate syntax in-place: point it
at an existing test project and apply the suggested fixes.
Install the .NET 10 SDK. Mockolate leverages C# 14 extension members (the projects can still target any supported framework). Then add the package:
dotnet add package Mockolateusing Mockolate;
public interface IChocolateDispenser
{
bool Dispense(string type, int amount);
}
// Create a mock
IChocolateDispenser sut = IChocolateDispenser.CreateMock();
// Setup: Dispense returns true for any Dark chocolate request
sut.Mock.Setup.Dispense("Dark", It.IsAny<int>()).Returns(true);
// Act
bool success = sut.Dispense("Dark", 4);
// Verify
sut.Mock.Verify.Dispense("Dark", It.IsAny<int>()).Once();Full reference docs at docs.testably.org/Mockolate:
- Create mocks
- Setup: properties, methods, indexers, parameter matching
- Mock events
- Verify interactions
- Advanced features: protected members, static interface members, callbacks, monitors, scenarios, unexpected-interaction checks
- Special types:
HttpClient, delegates
