Bringing Jest-esque Snapshot testing to C#
Snapper is a NuGet library which captures snapshots of objects to simplify testing. It is very heavily based on Jest Snapshot Testing.
Currently Snapper consists of three different NuGet packages for extensibility.
Choose the package which best fits your needs
- Snapper.Core: Basic snapshot functionality. Stores snapshots in bytes. Use for extending Snapper.
- Snapper.Json: Extends Snapper.Core to provide storing snapshots in Json format
- Snapper.Json.Xunit: Extends Snapper.Json and integrates with the XUnit testing framework.
Install the package through NuGet
nuget install <package_name>
// Create class which implements IAssert
var asserter = new ClassWhichImplementsIAssert();
var snapper = new Snapper(asserter, directoryToStoreSnapshots);
// the object to snapshot must be marked as `Serializable`
snapper.Snap("snapshotName", objectToSnapshot);
To update snapshots set the Environment Variable UpdateSnapshots
to true
and run the tests.
// Create class which implements IAssert
var asserter = new ClassWhichImplementsIAssert();
var snapper = new JsonSnapper(asserter, directoryToStoreSnapshots);
snapper.Snap("snapshotName", objectToSnapshot);
To update snapshots set the Environment Variable UpdateSnapshots
to true
and run the tests.
This package extends Snapper.Json
to provide integration with the XUnit
testing framework.
// Snapshot name will be the same as the name of the test
XUnitSnapper.MatchSnapshot(objectToSnapshot);
XUnitSnapper.MatchSnapshot(snapshotName, objectToSnapshot);
To update snapshots set the Environment Variable UpdateSnapshots
to true
and run the tests.
You can also add the [UpdateSnapshots]
attribute to your test and run it. (Remember to remove it before you commit your code)
Write testsExtend XUnit Assert e.g.Assert.Snap(obj)
rather thanXUnitSnapper.Snap(obj)
- Write wiki docs
Update appveyor to build on every commit and publish nuget on tag- Create sample project
Publish to NugetAdd tags to Nuget- Add logo to Nuget
Downgrade project to lowest .net standard possibleDowngrade nuget dependencies to lowest possible- Create PR and Issue templates