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. Adds extensions to XUnit Assert.
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 XUnits Assert
class and therefore conflicts with xunit.assert
package.
You can safely remove the xunit.assert
package and just use what is imported through this package.
// Snapshot name will be the same as the name of the test
Assert.MatchSnapshot(objectToSnapshot);
Assert.MatchSnapshot(snapshotName, objectToSnapshot);
To update snapshots set the Environment Variable UpdateSnapshots
to true
and run the tests.
You can also add the [UpdateTestSnapshot]
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
- Write method/class 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