Snapshot testing library made for java. Inspired by my frontend colleague. Let me quote "Seriously Do you really write all those assertions? Don't you have Jest in java
It is:
- Simple
- Framework agnostic
- Lightweight
- Verbose
- Zero config ( well optionally you can write single line of configuration that will make your life helluva better
- Import the library
import com.github.michaelloo35.jsnap.SnapshotAssertConfiguration;
- (Optional) Configure path to resources directory relative to project root. With this one line of configuration your error messages will be nicely clickable. For single module maven project that would be:
SnapshotAssertConfiguration.setMavenModuleRelativeResourcesPath("/src/test/resources/");
- Write some assertions
expect(actual).toMatchSnapshot("snapshotFileNameGoesHere");
After running the test for the first time snapshot file will be generated under execution/current directory. This file should be verified and moved to resources:
From now on the test will assert actual against the snapshot and point out any differences or pass if there are any.