Kotlin Multiplatform (pending KSP support) snapshot (klip) manager for tests
- core - runtime library
- processor - ksp-based annotation processor to enable runtime work
- gradle-plugin - a gradle plugin to manage dependencies, config and ksp
- sandbox - a preconfigured sandbox to try out the setup without having to publish stuff
- Apply the plugin
plugins {
id("dev.petuska.klip") version "<version>"
}
- (Optional) Configure the plugin extension
klip {
root = File("some/custom/sources/root/src") // Unlikely to ever be anything but "./src" (default)
update = false // If set to true will overwrite the klips when running tests. Avoid hard-coding this.
}
- Annotate your test classes where you want to use klips with
@dev.petuska.klip.Klippable
Most of the DSL configuration options can also be set/overridden via gradle properties
./gradlew <some-task> -Pprop.name=propValue
, gradle.properties
or ~/.gradle/gradle.properties
. Bellow is the full
list of supported properties:
klip.root
klip.update
- Run tests as normal and use generated klip assertions such
as
assertKlip(id = "some id unique in test class scope", actual = MyActualValue())
. New klips will always be written to files, whereas existing ones (identified by test class scope and given id) will be read and used for assertions. - When the actual value changes, tests will fail since they do not match previous klip. In such cases inspect the
differences and if everything is as expected, re-run test(s) with klip updates enabled. This is done by either
passing a gradle prop
./gradlew test -Pklip.update
or setting an environment variableKLIP_UPDATE=true ./gradlew test
.