Skip to content

WickedFlame/Polaroider

Repository files navigation

Polaroider

Automated Snapshottesting for .NET

Build status Build status

NuGet Version NuGet Version

Maintainability Rating Coverage

Codacy Badge

Simplify UnitTesting with snapshots.
Polaroider is a Approval Testing Framework that creates and compares snapshots of objects.
This makes testing of objects and their content easy and fast.

// arrange
var repository = new PersonRepository();

// act
var person = repository.LoadTestPerson(...);

// assert
person.MatchSnapshot();

Testing with Snapshots

Snashots help when testing objects or large strings

  • Snapshots ensure that object structure does not change unintendedly. When adding or removing properties in objects, these are automatically captured and asserted.
  • Sanpshots ensure the state of objects. Allways ensure the atomic state of obejcts. Any changes to the data contained in the properties of the matched object is automatically validated and asserted.
  • Simplify comparing big strings. Just create a snapshot of the string and ensure it does not change in any future testrun.

Visit https://wickedflame.github.io/Polaroider/ for the full documentation.

Troubleshooting

When having trouble generating Snapshots or the TestMethodNotFoundException is thrown, please make sure that the option for Optimize code is disabled and *.pdb files are generated. For more information visit https://wickedflame.github.io/Polaroider/troubleshooting

Update from v1 to v2

v1 was focused on simplicity. v2 is focused on flexibility while maintaining simplicity.

There are some breaking changes when updating to v2.

Mapping of simple types

  • DateTimes are mapped in the ISO 8601 format to be Culture-Independent
  • Null strings are now displayed as null
  • Empty strings are now displayed as ''

Before updating to v2 ensure that all tests are executed without errors. If some tests throw a MismatchException there are two possibilities:

  • Update the snapshots with the UpdateSnapshot Attribute
  • Set the UseBasicFormatters on the SnapshotOptions. This resets all Formatters to the same as were used in v1
SnapshotOptions.Setup(o =>
{
    o.UseBasicFormatters();
});