/JSnap

Snapshot testing made for java

Primary LanguageJavaMIT LicenseMIT

JSnap

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

Maven release

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

How to use it:

  1. Import the library
import com.github.michaelloo35.jsnap.SnapshotAssertConfiguration;
  1. (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/");
  1. 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: Initial run

From now on the test will assert actual against the snapshot and point out any differences or pass if there are any. Changed value