Installation
You install three things: the core, one container adapter for your DI container (or the trivial Bag), and — if your tests use mocks — one mock adapter for your mocking library.
A minimal unit-test setup
Section titled “A minimal unit-test setup”Core + Microsoft DI + NSubstitute is a common starting point:
dotnet add package Mokkit --prereleasedotnet add package Mokkit.Containers.Microsoft.Extensions.DependencyInjection --prereleasedotnet add package Mokkit.Containers.NSubstitute --prerelease<ItemGroup> <PackageReference Include="Mokkit" Version="0.3.0-preview.1" /> <PackageReference Include="Mokkit.Containers.Microsoft.Extensions.DependencyInjection" Version="0.3.0-preview.1" /> <PackageReference Include="Mokkit.Containers.NSubstitute" Version="0.3.0-preview.1" /></ItemGroup>The [MokkitCapture] source generator ships inside the Mokkit package (under analyzers/dotnet/cs),
so referencing Mokkit is all you need to use it — nothing extra to install.
Package matrix
Section titled “Package matrix”| Package | You need it when… |
|---|---|
Mokkit |
Always. The core: Stage, Arrange/Act/Inspect, captures, the [MokkitCapture] generator. |
Mokkit.Containers.Microsoft.Extensions.DependencyInjection |
Your system-under-test is wired with Microsoft DI. |
Mokkit.Containers.Autofac |
…wired with Autofac. |
Mokkit.Containers.CastleWindsor |
…wired with Castle Windsor. |
Mokkit.Containers.Bag |
You just need to hold a few pre-built instances (e.g. e2e clients) — no DI, no auto-wiring. |
Mokkit.Containers.Moq |
Your tests mock with Moq. |
Mokkit.Containers.NSubstitute |
…mock with NSubstitute. |
Mokkit.Containers.FakeItEasy |
…mock with FakeItEasy. |
Mokkit.Containers.Common |
Shared base for the mock adapters — pulled in automatically; you don’t reference it directly. |
How to choose
Section titled “How to choose”- Which container adapter? Match your production wiring. If the SUT is resolved from Microsoft DI, use the Microsoft DI adapter so the real graph is exercised and mocks are bridged into it. If your test only needs to hand back a couple of pre-built objects (typical for black-box e2e), the Bag container is the zero-dependency choice.
- Which mock adapter? Match your mocking library — one per test project. (You can even mix a mock container with a DI container; see Containers & the mock→DI bridge.)
- Multiple SUTs? One test project can use several containers together; you compose them when you build the Stage. See The Stage & lifecycle.
Ready to write one? Head to the Quickstart.