SnapshotAssertions.TUnit
0.2.0
Prefix Reserved
See the version list below for details.
dotnet add package SnapshotAssertions.TUnit --version 0.2.0
NuGet\Install-Package SnapshotAssertions.TUnit -Version 0.2.0
<PackageReference Include="SnapshotAssertions.TUnit" Version="0.2.0" />
<PackageVersion Include="SnapshotAssertions.TUnit" Version="0.2.0" />
<PackageReference Include="SnapshotAssertions.TUnit" />
paket add SnapshotAssertions.TUnit --version 0.2.0
#r "nuget: SnapshotAssertions.TUnit, 0.2.0"
#:package SnapshotAssertions.TUnit@0.2.0
#addin nuget:?package=SnapshotAssertions.TUnit&version=0.2.0
#tool nuget:?package=SnapshotAssertions.TUnit&version=0.2.0
SnapshotAssertions.TUnit
Scope: Test projects only. Not intended for production code.
TUnit-native text-snapshot assertions on top of TUnit's [AssertionExtension] source generator. AOT-compatible, trimmable, no reflection. Coexists with Verify; does not replace it for object-graph cases.
Full documentation, full options reference, design notes, and roadmap: github.com/JohnVerheij/SnapshotAssertions.TUnit
Install
dotnet add package SnapshotAssertions.TUnit
SnapshotAssertions (the framework-agnostic core) comes transitively. Requirements: TUnit 1.43.11 or later, .NET 10.
Quick start
using SnapshotAssertions;
using PublicApiGenerator;
[Test]
public async Task Public_api_surface_matches_baseline()
{
var assembly = typeof(MyLib.Foo).Assembly;
var actual = ApiGenerator.GeneratePublicApi(assembly);
await Assert.That(actual).MatchesSnapshot();
}
The default file resolver writes Snapshots/{TestClassName}.{TestMethodName}.expected.txt. On mismatch, *.actual.txt is written next to the expected file and the assertion failure includes both paths plus a line-based diff.
Accept-changes workflow
Three modes, in order of preference:
- IDE diff-and-merge. Most IDEs (Rider, VS Code) detect side-by-side
.expected.txtand.actual.txtfiles and offer a diff-and-merge view. - Manual
cp.cp Snapshots/MyTest.actual.txt Snapshots/MyTest.expected.txt. - Bulk accept.
SNAPSHOT_ACCEPT=1 dotnet test. Refuses to run ifCI=true(so a slipped pipeline env never accepts silently).
CI never sets SNAPSHOT_ACCEPT. Mismatches always fail the build in pipelines.
Scrubbers (v0.2.0+)
For snapshots that contain volatile values (GUIDs, ISO 8601 timestamps, Unix-epoch-millis numbers, request IDs, etc.), chain .WithScrubber(...) calls to replace them with stable indexed tokens before comparison. Recurring values share an index; different kinds maintain independent counters.
using SnapshotAssertions;
// Curated default: Guid + Iso8601Timestamp + UnixEpochMillis
await Assert.That(jsonResponse)
.MatchesSnapshot()
.WithScrubber(Scrubbers.Default);
// Custom regex: replace request-id headers with a literal token
await Assert.That(httpLog)
.MatchesSnapshot()
.WithScrubber(Scrubbers.Pattern(@"\brequest-id=[a-f0-9-]+", "request-id=<scrubbed>"));
The built-in indexed scrubbers (Scrubbers.Guid, Scrubbers.Iso8601Timestamp, Scrubbers.UnixEpochMillis) emit <kind:N> tokens where N is assigned by first-occurrence order per kind. The same value at every site keeps the same N. Scrubbers.Pattern(...) overloads emit a literal token (no indexing).
Full Scrubbers reference, custom-scrubber recipe, and design notes on GitHub.
Why not Verify
Verify is excellent for object-graph diffing, scrubbers, IDE-integrated diff display. It remains the right choice when those features matter. SnapshotAssertions covers the text-snapshot 80% case without:
- Verify's
<Deterministic>false</Deterministic>requirement (which on Linux runners breaksMicrosoft.CodeCoverage's instrumentation pipeline; documented at TUnit#4149) - The 30-50 lines of per-project file-compare scaffolding consumers otherwise reproduce in every repo
The two libraries can coexist in the same test project; this package does not depend on Verify.
License
MIT — Copyright (c) 2026 John Verheij
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- SnapshotAssertions (>= 0.2.0)
- TUnit.Assertions (>= 1.43.11)
- TUnit.Core (>= 1.43.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See CHANGELOG.md