ScreenshotTestSuite

Added in 9.5.0-alpha03

@Incubating
interface ScreenshotTestSuite


A test suite to run Compose screenshot tests.

A ScreenshotTestSuite configures the execution environment and inputs required to render Compose previews and execute screenshot tests.

Example usage:

android {
testOptions {
screenshotTests {
create("myScreenshotTest") {
engineVersion = "1.0.0"
imageDifferenceThreshold = 0.0001f
targetVariants.add("debug")
dependencies {
implementation(project(":my-test-helpers"))
}
}
}
}
}

Summary

Public functions

Unit

Configures the dependencies for this test suite.

Public properties

String?

The version of the screenshot validation engine.

Float?

The maximum allowed percentage difference between the reference image and the rendered image for a screenshot test to pass.

MutableList<String>

Defines which variants this test suite targets.

Public functions

dependencies

Added in 9.5.0-alpha03
@Incubating
fun dependencies(action: AgpTestSuiteDependencies.() -> Unit): Unit

Configures the dependencies for this test suite.

Dependencies are added to the test suite's host (JVM) execution classpath. This enables the screenshot tests to access custom test helpers and preview providers during rendering.

Public properties

engineVersion

Added in 9.5.0-alpha03
var engineVersionString?

The version of the screenshot validation engine.

Specifies the version of the com.android.tools.screenshot:screenshot-validation-junit-engine artifact (published on the Google Maven repository) to use for layout rendering and screenshot validation.

This property is mandatory. A valid version must be provided; otherwise, a Gradle sync error will be reported.

imageDifferenceThreshold

Added in 9.5.0-alpha03
var imageDifferenceThresholdFloat?

The maximum allowed percentage difference between the reference image and the rendered image for a screenshot test to pass.

Specified as a floating-point value between 0.0f (exact match required) and 1.0f (100% difference allowed). For example, a value of 0.0001f represents a 0.01% difference threshold.

If null, the default engine threshold (0.0f) will be used.

targetVariants

Added in 9.5.0-alpha03
val targetVariantsMutableList<String>

Defines which variants this test suite targets.