snapshooter
snapshooter copied to clipboard
Reuse Snapshot across multple tests.
Sometimes multiple tests produce equal snapshots... And it needs to be checked.
How about add possiblity to match against different test snapshot or common snapshot?
I think you can already by setting the snapshot name explicitly
example
[Fact]
public void SomeTest()
{
// arrange
var serviceClient = new ServiceClient();
// act
TestPerson person = serviceClient.CreatePerson(
Guid.Parse("1192F21C-8501-4771-A070-C79C7C7EF411"), "Albert", "Einstein");
// assert
// Snapshot name is MyCommonSnap.snap
Snapshot.Match(person, "MyCommonSnap");
}
[Fact]
public void SomeOtherTest()
{
// arrange
var serviceClient = new ServiceClient();
// act
TestPerson person = serviceClient.CreatePerson(
Guid.Parse("1192F21C-8501-4771-A070-C79C7C7EF411"), "Albert", "Einstein");
// assert
// Snapshot name is MyCommonSnap.snap
Snapshot.Match(person, "MyCommonSnap");
}
Thank you for this example! Little problem here... Two tests write single mismatch snapshot.
Will be enough one test that writes.
[Fact]
public void SomeTest()
{
// arrange
var serviceClient = new ServiceClient();
// act
TestPerson person = serviceClient.CreatePerson(
Guid.Parse("1192F21C-8501-4771-A070-C79C7C7EF411"), "Albert1", "Einstein");
// assert
// Snapshot name is MyCommonSnap.snap
Snapshot.Match(person, "MyCommonSnap");
}
[Fact]
public void SomeOtherTest()
{
// arrange
var serviceClient = new ServiceClient();
// act
TestPerson person = serviceClient.CreatePerson(
Guid.Parse("1192F21C-8501-4771-A070-C79C7C7EF411"), "Albert2", "Einstein");
// assert
// Snapshot name is MyCommonSnap.snap
Snapshot.Match(person, "MyCommonSnap", createMismathSnapshot: false);
}
}
@s-tarasov how would your desired solution look like?
Something like this would be possible but is ugly IMO since you would have to rename the snapshot manually when you wan't to override the current snapshot. /mismatch/ - MyCommonSnap.SomeTest.snap - MyCommonSnap.SomeOtherTest.snap
I sugest add new option createMismathSnapshot
with default vaue true.
In main test:
Snapshot.Match(person, "MyCommonSnap");
In secondary tests:
Snapshot.Match(person, "MyCommonSnap", createMismathSnapshot: false);
/mismatch/
- MyCommonSnap.snap
Second soultion add new option mismatchSnapSufix
.
In main Test:
Snapshot.Match(person, "MyCommonSnap");
In secondary Tests:
Snapshot.Match(person, "MyCommonSnap", mismatchSnapSufix:"SecondaryTest");
/mismatch/
- MyCommonSnap.snap
- MyCommonSnap.SecondaryTest.snap