Mockolate

May 10, 2026 · View on GitHub

Mockolate logo

Nuget Build Quality Gate Status Coverage Mutation 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

using 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();

Documentation

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