Skip to content

Repository files navigation

Mockolate

Mockolate logo

NugetBuildQuality Gate StatusCoverageMutation testing badge

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.

Why Mockolate

Reflection-based mocks (Moq, NSubstitute, …)Mockolate
AOT / trimmingnot supportedsupported
Validationruntime exceptionsanalyzers + compile errors
Setup APIExpression<Func<…>> treesregular method calls
Hot pathdynamic-proxy dispatchdirect 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.

Installation

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 Mockolate

Quick Start

usingMockolate;publicinterfaceIChocolateDispenser{boolDispense(stringtype,intamount);}// Create a mockIChocolateDispensersut=IChocolateDispenser.CreateMock();// Setup: Dispense returns true for any Dark chocolate requestsut.Mock.Setup.Dispense("Dark",It.IsAny<int>()).Returns(true);// Actboolsuccess=sut.Dispense("Dark",4);// Verifysut.Mock.Verify.Dispense("Dark",It.IsAny<int>()).Once();

Documentation

Full reference docs at docs.testably.org/Mockolate:

About

A modern, strongly-typed, AOT-compatible mocking library for .NET, powered by source generators.

Resources

Code of conduct

Contributing

Stars

10 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Contributors

Languages