SnapshotAssert 0.4.0

dotnet add package SnapshotAssert --version 0.4.0
                    
NuGet\Install-Package SnapshotAssert -Version 0.4.0
                    
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="SnapshotAssert" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SnapshotAssert" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="SnapshotAssert" />
                    
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 SnapshotAssert --version 0.4.0
                    
#r "nuget: SnapshotAssert, 0.4.0"
                    
#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 SnapshotAssert@0.4.0
                    
#: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=SnapshotAssert&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=SnapshotAssert&version=0.4.0
                    
Install as a Cake Tool

SnapshotAssert

A minimal snapshot-testing library for xUnit v3, byte-for-byte compatible with the default text format of Verify.

SnapshotAssert serializes objects with System.Text.Json contract metadata and compares the rendered output against .verified.txt files stored next to the test. On mismatch it writes a .received.txt file and launches your diff tool via DiffEngine.

Scope

  • xUnit v3 only (test identity via TestContext.Current).
  • Supports the Verify API subset used by its consuming projects: Verify(object), Verify(object, VerifySettings), VerifyJson(string), UseParameters, UseFileName, and the inventoried VerifySettings scrubbing/serialization methods.
  • No Argon/Json.NET dependency.

Requirements and limitations

  • Snapshot files are located via the compile-time caller file path ([CallerFilePath]). Test projects must not enable DeterministicSourcePaths (implied by ContinuousIntegrationBuild=true), which rewrites source paths to /_/... and makes the snapshot directory unresolvable. SnapshotAssert fails with a descriptive error when it detects this.

  • Empty string values render with a trailing separator space (Name: ), matching Verify. Editors configured to trim trailing whitespace on save can silently corrupt such snapshots; protect them via .editorconfig:

    [*.{received,verified}.txt]
    trim_trailing_whitespace = false
    insert_final_newline = false
    

Releasing

  1. Open a pull request that bumps <Version> in src/SnapshotAssert/SnapshotAssert.csproj and merge it.

  2. Tag the merge commit and push the tag:

    git tag v<version>
    git push origin v<version>
    
  3. The release.yml workflow revalidates the tagged commit (build, unit tests, pack, package-consumer tests) and publishes the package to nuget.org.

The tag must match the csproj version exactly (v0.2.0 requires <Version>0.2.0</Version>); a mismatch fails the release before any publish. Publishing a version that already exists on nuget.org also fails — bump the version instead of re-tagging.

Local packaging note

tests/SnapshotAssert.PackageConsumer restores SnapshotAssert exclusively from the local artifacts/ feed (dotnet pack src/SnapshotAssert/SnapshotAssert.csproj -o artifacts). When repacking the same version locally, NuGet may serve a stale copy from the global cache; clear it with dotnet nuget locals global-packages --clear.

Migrating a project from Verify.XunitV3

  1. Replace the Verify.XunitV3 package reference with SnapshotAssert.
  2. Remove using Argon; from settings builders. NullValueHandling and DefaultValueHandling keep their names, so AddExtraSettings lambda bodies compile unchanged.
  3. Ensure .gitattributes contains *.verified.txt text eol=lf and re-checkout the snapshots if the working tree has CRLF endings. Verified files containing carriage returns fail fast, exactly as in Verify.
  4. Build via the solution file so $(SolutionDir) is defined; the {SolutionDirectory} scrub token in snapshots requires it.
  5. Run the test suite. Existing .verified.txt files must pass unchanged; any mismatch is a SnapshotAssert bug, not a snapshot to re-approve.

Acknowledgements

  • SnapshotAssert is built based on Verify: its API, snapshot format, and approval workflow are the model for this library.
  • The project was built with Claude Code and OpenSpec.
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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 69 7/13/2026
0.3.0 77 7/12/2026
0.2.0 67 7/12/2026
0.1.0 66 7/12/2026