SnapshotAssertions 0.7.1

Prefix Reserved
dotnet add package SnapshotAssertions --version 0.7.1
                    
NuGet\Install-Package SnapshotAssertions -Version 0.7.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SnapshotAssertions" Version="0.7.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SnapshotAssertions" Version="0.7.1" />
                    
Directory.Packages.props
<PackageReference Include="SnapshotAssertions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SnapshotAssertions --version 0.7.1
                    
#r "nuget: SnapshotAssertions, 0.7.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SnapshotAssertions@0.7.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SnapshotAssertions&version=0.7.1
                    
Install as a Cake Addin
#tool nuget:?package=SnapshotAssertions&version=0.7.1
                    
Install as a Cake Tool

SnapshotAssertions

NuGet License: MIT .NET

Scope: Test projects only. Not intended for production code.

Framework-agnostic core for text-snapshot assertions.

For TUnit test projects, install SnapshotAssertions.TUnit instead; this package comes with it transitively. SnapshotAssertions is the framework-agnostic shared engine; framework-specific adapter packages add the assertion entry points each test framework expects.


What's in this package

  • SnapshotComparer: string-against-file comparison with line-ending, BOM, trailing-whitespace, and trailing-newline options.
  • SnapshotFileResolver: TestContext-aware default file naming (Snapshots/{TestClass}.{TestMethod}.expected.txt) and explicit-path resolution.
  • SnapshotAcceptMode: env-var-driven accept logic (SNAPSHOT_ACCEPT=1 writes the actual content over the expected baseline) with a CI=true guard so accidental pipeline acceptance is impossible.
  • SnapshotOptions: line-ending, BOM, whitespace, and trailing-newline configuration with strict defaults, plus a caller-supplied WithNormalizer(Func<string, string>) pre-comparison transform (v0.5.0+).
  • LineDiffRenderer: terminal line-based diff display, truncated to the first 20 differing lines for very large diffs (LineDiffRenderer.MaxDifferingLines = 20).
  • SnapshotScrubber + Scrubbers factory (v0.2.0+): text-transform pipeline that replaces volatile substrings (GUIDs, ISO 8601 timestamps, Unix-epoch-millis numbers, custom regex matches) with stable indexed tokens before comparison. Built-ins (Scrubbers.Guid, Scrubbers.Iso8601Timestamp, Scrubbers.UnixEpochMillis, plus Scrubbers.GuidN and Scrubbers.ElapsedMs (v0.4.0+)), curated chains (Scrubbers.Default for the v0.2.0 three-pattern set, Scrubbers.Common (v0.4.0+) for the extended five-pattern set), two Scrubbers.Pattern overloads for custom regex (flat literal token) plus two Scrubbers.IndexedPattern overloads (v0.5.0+) for the indexed <kind:N> counterpart that keeps recurring matched values correlated, and SnapshotScrubberState for stable indexed-token assignment across recurring values. Scrubbers.Combine(params SnapshotScrubber[]) (v0.3.0+) assembles an array of scrubbers into a single composite for reusable bundles.
  • DiffSuggestion + DiffSuggestionAnalyzer (v0.4.0+): scans a snapshot-mismatch diff for known volatile patterns and surfaces scrubber recommendations. Integrated into SnapshotResult.Describe() so failure messages include a top-3-capped "Suggestion(s)" section pointing at applicable built-ins.
  • SnapshotAssertions.Render.SnapshotRenderer<T> + Renderer.For<T> (v0.4.0+): abstract base class and inline factory for projecting domain types to canonical strings before snapshot comparison. Adapter packages consume these via their own MatchesSnapshot<T> overloads.

Test-framework adapters

Package Test framework Status
SnapshotAssertions.TUnit TUnit Available now
SnapshotAssertions.NUnit NUnit Possible if there is demand
SnapshotAssertions.xUnit xUnit Possible if there is demand
SnapshotAssertions.MSTest MSTest Possible if there is demand

If you'd find a non-TUnit adapter useful, open a feature request: adapters are not built proactively.

Installation

dotnet add package SnapshotAssertions.TUnit

SnapshotAssertions comes transitively. You don't need to install it directly unless you're building your own adapter package.

Stability

The public surfaces above are semver-bound. Breaking changes require a major version bump. The exact text format of line-based diff output is not stable and may gain extra detail or change formatting in any release.

License

MIT. Copyright (c) 2026 John Verheij.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SnapshotAssertions:

Package Downloads
SnapshotAssertions.TUnit

TUnit-native text-snapshot assertions using [AssertionExtension]. Provides Assert.That(actual).MatchesSnapshot() / .MatchesSnapshotFile() with line-based diff display, accept-via-environment-variable workflow, and CI guard. AOT-compatible, trimmable, no reflection. Designed for API-surface verification and small text snapshots; coexists with Verify for object-graph cases.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.1 5,175 6/14/2026
0.7.0 693 6/14/2026
0.6.2 380 6/12/2026
0.6.1 626 6/5/2026
0.6.0 275 6/4/2026
0.5.0 146 6/3/2026
0.4.0 1,529 5/16/2026
0.3.0 526 5/12/2026
0.2.0 300 5/7/2026
0.1.0 196 5/5/2026

View the rendered release notes: https://github.com/JohnVerheij/SnapshotAssertions.TUnit/releases/tag/v0.7.1

Patch release. Restores `build/SnapshotAssertions.TUnit.targets` to the package. 0.7.0 shipped without it, so a consumer's committed `Snapshots/*.expected.txt` baselines stopped copying to the test output directory and every snapshot assertion failed with "baseline does not exist". No public API change.

### Fixed

- **The package again ships `build/SnapshotAssertions.TUnit.targets`.** DotNetProjectFile.Analyzers 1.15.0 added `**/*.targets` to a SonarQube content glob marked `Pack="false"`, which silently overrode this package's explicit `Pack="true"` for its own build targets and dropped the file from the 0.7.0 `.nupkg`. That targets file auto-includes a consumer's `Snapshots/**/*.expected.txt` with `CopyToOutputDirectory="PreserveNewest"`, so without it the committed baselines never reach the test binary's output directory and the resolver reports them missing. Setting `SonarQubeIntegration=false` (the integration is unused in this package) restores the packed asset, and a CI check now asserts the produced `.nupkg` contains the build targets so it cannot silently drop again.

### Upgrade note

Consumers who applied the 0.7.0 workaround (a manual `<None Update="Snapshots/**/*.expected.txt" CopyToOutputDirectory="PreserveNewest" />` together with `<SnapshotAssertionsAutoIncludeSnapshots>false</SnapshotAssertionsAutoIncludeSnapshots>`) can remove both after upgrading; the package's own targets resume handling the copy. Leaving the workaround in place stays harmless.