aweXpect.Snapshots.DiffEngine 4.0.0-beta.0.pre.3

Prefix Reserved
This is a prerelease version of aweXpect.Snapshots.DiffEngine.
dotnet add package aweXpect.Snapshots.DiffEngine --version 4.0.0-beta.0.pre.3
                    
NuGet\Install-Package aweXpect.Snapshots.DiffEngine -Version 4.0.0-beta.0.pre.3
                    
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="aweXpect.Snapshots.DiffEngine" Version="4.0.0-beta.0.pre.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="aweXpect.Snapshots.DiffEngine" Version="4.0.0-beta.0.pre.3" />
                    
Directory.Packages.props
<PackageReference Include="aweXpect.Snapshots.DiffEngine" />
                    
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 aweXpect.Snapshots.DiffEngine --version 4.0.0-beta.0.pre.3
                    
#r "nuget: aweXpect.Snapshots.DiffEngine, 4.0.0-beta.0.pre.3"
                    
#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 aweXpect.Snapshots.DiffEngine@4.0.0-beta.0.pre.3
                    
#: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=aweXpect.Snapshots.DiffEngine&version=4.0.0-beta.0.pre.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=aweXpect.Snapshots.DiffEngine&version=4.0.0-beta.0.pre.3&prerelease
                    
Install as a Cake Tool

aweXpect.Snapshots

Nuget

aweXpect.Snapshots compares strings and objects with reviewed snapshots, which are stored next to the tests or in a store of your own, e.g. to verify generated text or a complex result without writing out the expected value.

Installation

dotnet add package aweXpect.Snapshots

The packages bring Expect.That with them, but not the expectations for strings, numbers or collections, so reference aweXpect as well. MatchesSnapshot and MatchesPublicApiSnapshot live in the namespace aweXpect; OrphanedSnapshots, SnapshotAcceptance, SnapshotRule and the customization need using aweXpect.Snapshots;.

At a glance

// compare a string with the snapshot that is stored next to the test
await Expect.That(description).MatchesSnapshot();

// compare an object, written completely and indented by the aweXpect formatter
await Expect.That(album).MatchesSnapshot();

// compare an exception member-wise, without members that vary per build or machine, like the stack trace
await Expect.That(() => player.Play(album, -1)).Throws<ArgumentOutOfRangeException>().Which.MatchesSnapshot();

// replace values that change from run to run before comparing
await Expect.That(playlist).MatchesSnapshot().For.Text(@"plays=\d+").AsRegex().Mask("plays=<count>");

// replace every Guid and ISO 8601 date with a numbered placeholder ({Guid_1}, {Date_1}, …)
await Expect.That(playlist).MatchesSnapshot().For.Guids().Mask().For.Dates().Mask();

// leave out, mask or convert members of an object, selected by their name, type or declaring type
await Expect.That(album).MatchesSnapshot()
    .For.Members().WithName("PlayCount").Ignore()
    .For.Members().WithName("Id").Mask()
    .For.Members().DeclaredIn<Album>().WithName("Released").OfType<DateTime>().Convert(date => date.Year);

// store a JSON string as AlbumTests.Describes.awexpect-snapshot.json for syntax highlighting
await Expect.That(json).MatchesSnapshot().WithExtension("json");

// keep a snapshot per target framework and operating system
// (AlbumTests.Describes@net8.0@windows.awexpect-snapshot.txt)
await Expect.That(exception.Message).MatchesSnapshot()
    .UniqueFor.TargetFramework().UniqueFor.OperatingSystem();

// verify the public API of an assembly, written as C# declarations
// (package aweXpect.Snapshots.PublicApi)
await Expect.That(typeof(Album).Assembly).MatchesPublicApiSnapshot()
    .UniqueFor.TargetFramework();

The snapshot is stored as <TestFile>.<Method>.awexpect-snapshot.txt next to the test file, where <TestFile> is the name of the test file without its extension. A missing or different snapshot fails the test and writes the actual value to <TestFile>.<Method>.awexpect-snapshot.pending.txt; rename it to <TestFile>.<Method>.awexpect-snapshot.txt to accept it, or set the environment variable AWEXPECT_ACCEPT_SNAPSHOTS to all to accept all changed snapshots of a test run (or to new to only add the missing ones).

Before the first run, the snapshot of description does not exist yet, so the expectation fails with:

Expected that description
matches the snapshot "/src/Tests/AlbumTests.Describes.awexpect-snapshot.txt",
but the snapshot did not exist

Actual:
Abbey Road by The Beatles

Pending snapshot:
/src/Tests/AlbumTests.Describes.awexpect-snapshot.pending.txt

Overview

Expectations for string and any other object:

Expectation Negated Summary
MatchesSnapshot a string matches the snapshot stored next to the test, with rules for its lines and text
MatchesSnapshot an object matches its snapshot, written by aweXpect, with rules for its members and text

Expectations for Assembly and FileInfo, from aweXpect.Snapshots.PublicApi:

Expectation Negated Summary
MatchesPublicApiSnapshot the public API of the assembly, or of the assembly in the file, matches the snapshot

Customization

Set a value under Customize.aweXpect.Snapshots() for the current async flow, or under Customize.aweXpect.Global.Snapshots() for all tests.

Value Default Summary
Acceptance null, left to the variable AWEXPECT_ACCEPT_SNAPSHOTS which missing or changed snapshots are accepted
Rules none the rules to mask or ignore values in every snapshot
Store a file next to the test file where the snapshots are kept
Comparers none decide whether a value matches its snapshot, e.g. for images
Reporters none are told about every missing, different or matching snapshot
NamedAfterTestArguments false names each snapshot after the arguments of the test case
AttachPendingFiles false attaches the pending file of a mismatch to the test result

Documentation

The full documentation is available at docs.testably.org:

  • Matching snapshots: strings, objects, exceptions, binary data and files, the file extension, encoding and line breaks
  • Accepting snapshots: reviewing the pending file, accepting all changes of a run and attaching the pending files on a build server
  • Diff tools: open a diff tool for a missing or different snapshot with DiffEngine, in which the change can be taken over into the snapshot
  • Naming snapshots: a snapshot per test case or environment, and nested under their test file in Rider and Visual Studio
  • Masking and ignoring values: mask, convert or leave out values that change from run to run
  • Orphaned snapshots: OrphanedSnapshots.CheckAsync() in the teardown of the test run reports the snapshots that no test uses any more on a build server, and deletes them while accepting all changes
  • Public API: MatchesPublicApiSnapshot from aweXpect.Snapshots.PublicApi
  • Advanced:
    • Storing snapshots elsewhere: a SnapshotStore instead of files next to the tests, e.g. a shared folder or a database
    • Comparers: decide whether a value matches its snapshot instead of the built-in comparison, e.g. an image comparer that tolerates small differences of single pixels
    • Reporters: are told about every missing, different or matching snapshot, e.g. to open a diff tool
    • Deterministic builds: how the snapshots are found when the build replaces the path of the repository with /_/
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
4.0.0-beta.0.pre.3 43 10/29/2026
4.0.0-beta.0.pre.2 44 10/27/2026
4.0.0-beta.0.pre.1 53 10/22/2026
0.6.0 95 10/19/2026
0.5.0 91 10/18/2026
0.4.0 86 10/18/2026
0.3.0 93 10/18/2026