Repository navigation
Releases
Releases · lolgab/snaptest
snaptest 0.1.0
Snapshot testing for Scala: record what your tests produce, review it as code, and catch changes as diffs.
Snapshots are stored as generated Scala sources in snapshots/ next to each test, so build tools rerun tests when a snapshot changes, and failures link to the snapshot's line.
Documentation: https://lolgab.github.io/snaptest/
Test frameworks
| Framework | Artifact | Mix in |
|---|---|---|
| munit | snaptest-munit |
MunitSnapshots |
| ScalaTest | snaptest-scalatest |
ScalaTestSnapshots, AsyncScalaTestSnapshots |
| uTest | snaptest-utest |
UTestSnapshots |
| specs2 | snaptest-specs2 |
Specs2Snapshots |
| munit-cats-effect | snaptest-munit-cats-effect |
CatsEffectSnapshots |
| weaver | snaptest-weaver |
WeaverSnapshots |
| ZIO Test | snaptest-zio |
ZioSnapshots |
Every artifact is published for Scala 3.9+, on the JVM, Scala.js 1 and Scala Native 0.5. snaptest-core holds the framework-independent parts.
// sbt
libraryDependencies += "com.github.lolgab" %%% "snaptest-munit" % "0.1.0" % Test
// Mill
def mvnDeps = Seq(mvn"com.github.lolgab::snaptest-munit::0.1.0")
// Scala CLI
//> using test.dep com.github.lolgab::snaptest-munit::0.1.0Highlights
assertSnapshotin any test, several times per test, keyed by test name; idiomatic APIs for each framework, likeassertIOSnapshotfor munit-cats-effect,expectSnapshotreturningIO[Expectations]for weaver andassertZIOSnapshotfor ZIO Test- Values rendered with pprint, strings stored verbatim, readable literals (plain, triple quotes or
stripMargin); customizable withSnapshotRender SNAPTEST=auto|always|prune|no, defaulting tonoon CI so snapshots are never recorded silently- Failures show a diff and link to the snapshot with
path:line - Snapshots of deleted tests are removed when every test of a suite ran and passed; with specs2, weaver and ZIO Test, use
SNAPTEST=pruneon a full run - Works with sbt, Mill and Scala CLI
Known limitations
- With Mill, Scala.js and Scala Native tests see the environment of the Mill daemon: run
./mill --no-daemonwhen settingSNAPTEST - A weaver suite defining its own
sharedResource, or a ZIO spec overridingaspects, keeps the snapshot hooks explicitly (see the guide)