Skip to content

tomasbjerre/assertj-snapshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AssertJ Snapshot

Maven Central

This library extends AssertJ with snapshot assertions. Inspired by the same feature in Jest.

Demo

Examples

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.

About

AssertJ extension adding support for snapshot testing

Resources

License

Stars

Watchers

Forks

Packages

No packages published