Arbeidstilsynet.Common.TestExtensions.Snapshots
0.2.1
Prefix Reserved
dotnet add package Arbeidstilsynet.Common.TestExtensions.Snapshots --version 0.2.1
NuGet\Install-Package Arbeidstilsynet.Common.TestExtensions.Snapshots -Version 0.2.1
<PackageReference Include="Arbeidstilsynet.Common.TestExtensions.Snapshots" Version="0.2.1" />
<PackageVersion Include="Arbeidstilsynet.Common.TestExtensions.Snapshots" Version="0.2.1" />
<PackageReference Include="Arbeidstilsynet.Common.TestExtensions.Snapshots" />
paket add Arbeidstilsynet.Common.TestExtensions.Snapshots --version 0.2.1
#r "nuget: Arbeidstilsynet.Common.TestExtensions.Snapshots, 0.2.1"
#:package Arbeidstilsynet.Common.TestExtensions.Snapshots@0.2.1
#addin nuget:?package=Arbeidstilsynet.Common.TestExtensions.Snapshots&version=0.2.1
#tool nuget:?package=Arbeidstilsynet.Common.TestExtensions.Snapshots&version=0.2.1
Arbeidstilsynet.Common.TestExtensions.Snapshots
Minimal snapshot testing for .NET and xunit v3.
The library serializes a value to readable text and compares it with a committed *.verified.txt file. On a mismatch it writes a *.received.txt file next to it and fails the test with a diff.
The snapshot format is compatible with Verify's snapshot format, so existing .verified.txt files can usually be reused unchanged. The library is a clean-room implementation and contains no Verify code. The full format and behaviour are specified in SPEC.md.
Usage
using Arbeidstilsynet.Common.TestExtensions.Snapshots;
public class SakRepositoryTests
{
[Fact]
public async Task Create_StoresSak()
{
var sak = await _repository.Create(...);
await Snapshot.Verify(sak, new SnapshotSettings().UseDirectory("Snapshots"));
}
}
This creates Snapshots/SakRepositoryTests.Create_StoresSak.verified.txt:
{
Id: Guid_1,
Opprettet: DateTimeOffset_1,
Status: Mottatt
}
Snapshot.Serialize(value, settings) returns the text without comparing it.
Settings
| Method | Effect |
|---|---|
UseDirectory(path) |
Store snapshots in path. A relative path is resolved from the test source file's directory. |
UseFileName(name) |
Override {Class}.{Method}{Parameters}. |
UseParameters(values) |
Override the theory arguments used in the file name. |
ScrubInlineGuids() |
Replace GUIDs inside longer strings with Guid_n. |
DontScrubGuids() |
Write Guid values as-is. |
DontScrubDateTimes() |
Write DateTime, DateTimeOffset, DateOnly and ISO date strings as-is. |
DontIgnoreEmptyCollections() |
Write empty collections as [] instead of omitting them. |
IncludeDefaultValues() |
Write null and default members. |
ScrubMembers(names) |
Write members, dictionary entries and claims with these names as {Scrubbed}. |
AddScrubber(Func<string, string>) |
Post-process the serialized text. |
Theory arguments from xunit v3's TestContext become part of the file name, e.g. Tests.Method_language=Bokmål.verified.txt.
Workflow
- Run the tests. New or changed snapshots fail and leave
*.received.*files. - Review the diff in the failure message (or diff the files in your IDE).
- Accept the changes in one of these ways:
- Rename
*.received.*to*.verified.*, or runscripts/accept-snapshots.sh [directory]from the dotnet-common repository. - Re-run with
SNAPSHOT_ACCEPT=1(orUPDATE_SNAPSHOTS=1). The verified files are overwritten and the tests pass. Accept mode is ignored whenCI=true.
- Rename
- Commit the
*.verified.*files. Add*.received.*to.gitignore.
Snapshot files are UTF-8 with BOM and \n line endings. Consider adding this to .gitattributes:
*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.png binary
Migrating from Verify
| Verify | Snapshots |
|---|---|
await Verify(value) |
await Snapshot.Verify(value) |
await Verify(value, settings) |
await Snapshot.Verify(value, settings) |
new VerifySettings() |
new SnapshotSettings() |
settings.UseDirectory(...), ScrubInlineGuids(), DontScrubGuids(), DontScrubDateTimes(), DontIgnoreEmptyCollections(), UseParameters(...), ScrubMembers(...) |
Same names |
.UseParameters(x) on the Verify(...) call |
settings.UseParameters(x) (xunit v3 theory arguments are picked up automatically) |
AddScrubber(StringBuilder => ...) |
AddScrubber(string => string) |
Deliberate differences are listed in SPEC.md §5.
Requirements
- .NET 10
- xunit v3 for test-name resolution. Other frameworks work with
UseFileName, or fall back to the calling file and member name.
| 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
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Arbeidstilsynet.Common.TestExtensions.Snapshots:
| Package | Downloads |
|---|---|
|
Arbeidstilsynet.Common.TestExtensions.Snapshots.Pdf
PDF snapshot testing (page text plus rendered page images compared with SSIM) for Arbeidstilsynet.Common.TestExtensions.Snapshots. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.1 | 231 | 10/15/2026 |
| 0.2.0 | 1,226 | 10/5/2026 |
| 0.2.0-alpha | 154 | 10/5/2026 |
| 0.1.0 | 232 | 10/5/2026 |
| 0.1.0-preview.1 | 62 | 10/5/2026 |
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added <!-- for new features. -->
### Changed <!-- for changes in existing functionality. -->
### Deprecated <!-- for soon-to-be removed features. -->
### Removed <!-- for now removed features. -->
### Fixed <!-- for any bug fixes. -->
### Security <!-- in case of vulnerabilities. -->
## 0.2.1
### Fixed
- Standardized NuGet metadata with Arbeidstilsynet as author, an MIT license expression, an embedded icon and Git repository details.
## 0.2.0
### Added
- feat: `SnapshotSettings.ScrubMembers(params string[])` writes the matching members, dictionary entries and claims as `{Scrubbed}`.
- feat: `System.Security.Claims.Claim` is written as `{ type: value }`, matching Verify.
### Fixed
- fix: `DateTime` / `DateTimeOffset` values on a whole minute are now written as `HH:mm`, matching Verify, instead of `HH:mm:ss`.
## 0.1.0
### Added
- feat: `Snapshot.Verify` and `Snapshot.Serialize`. These use a snapshot format compatible with Verify, the received/verified workflow and `SNAPSHOT_ACCEPT` / `UPDATE_SNAPSHOTS` accept mode.
- feat: `SnapshotSettings` with directory, file name, parameter, GUID and date scrubbing options and custom scrubbers.
- feat: `Snapshot.VerifyTargets` for multi-file snapshots, used by `Arbeidstilsynet.Common.TestExtensions.Snapshots.Pdf`.