Skip to content

Gradle snapshots

Requirements

The Tuist Gradle plugin uploads the images Paparazzi and Roborazzi record, and Tuist compares them with the baseline. In modules that apply Paparazzi, the plugin also generates a test that renders every Compose @Preview, so you don't write snapshot tests by hand.

Set up#

Enable snapshots in your settings.gradle.kts:

kotlin
tuist {
snapshots {
enabled = true
set = "android-phone" // Defaults to the Gradle project's path.
}
}

Run#

In CI, ./gradlew test renders the previews and uploads them, and the build fails when they changed and nobody approved the changes. Local runs upload nothing, because they would upload uncommitted changes. Pass -Ptuist.snapshots=false to turn uploads off in CI.

The Paparazzi and Roborazzi record tasks, such as recordPaparazziDebug, always upload when snapshots are enabled.

Options#

The snapshots block takes these options:

  • enabled: whether snapshots are uploaded. Defaults to false.
  • set: the set builds are compared within. Defaults to the Gradle project's path.
  • directory: the directory with the images to upload, relative to the Gradle project. Defaults to where the generated preview test or the snapshot library writes.
  • failOnChanges: whether the build fails on changes nobody approved. Defaults to true.
  • diffThreshold: the share of pixels, from 0 to 1, that may differ before an image counts as changed. Defaults to 0.
  • previews { generateTests }: whether the Compose preview test is generated. Defaults to true.
  • previews { packageTrees }: the packages scanned for previews. Defaults to the Android namespace.
  • previews { includePrivatePreviews }: whether private @Preview functions are rendered too. Defaults to false.
  • previews { theme }: the Android theme previews are rendered in. Defaults to Paparazzi's.