This library extends AssertJ with snapshot assertions. Inspired by the same feature in Jest.
There are running examples in the repository.
Assertions are made available by importing:
import static org.assertj.snapshot.api.Assertions.assertThat;
A snapshot can be recorded to a file, like this:
assertThat(anyObject)
.matchesSnapshot();
First time this code is run, a snapshot file will be created. Any future runs will verify against that snapshot.
A snapshot
can also be recorded inline, in the test case:
assertThat(anyObject)
.matchesInlineSnapshot();
When this is run, it will manipulate the test case and change it like this:
assertThat(anyObject)
.matchesInlineSnapshot("""
{
"someAttr1" : "abc",
"someAttr2" : 123
}
""");
Any future runs will verify against that snapshot.