From 14557ce9bb39dc551a3e135c4934c975dc6fae21 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 13 May 2025 01:06:28 -0700 Subject: [PATCH] Screenshot testing --- app/build.gradle.kts | 8 ++++++++ build.gradle.kts | 1 + gradle.properties | 3 ++- gradle/libs.versions.toml | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2adea3d..2bac279 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -3,6 +3,7 @@ plugins { alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.screenshot) id("kotlin-parcelize") } @@ -74,6 +75,12 @@ android { includeInApk = false includeInBundle = false } + experimentalProperties["android.experimental.enableScreenshotTest"] = true + testOptions { + screenshotTests { + imageDifferenceThreshold = 0.0001f // 0.01% + } + } } dependencies { @@ -135,4 +142,5 @@ dependencies { debugImplementation(libs.ui.test.manifest) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) + screenshotTestImplementation(libs.androidx.compose.ui.tooling) } diff --git a/build.gradle.kts b/build.gradle.kts index c875257..7342e18 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,4 +3,5 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.compose) apply false + alias(libs.plugins.screenshot) apply false } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 20e2a01..6eaed49 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,4 +20,5 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true +android.experimental.enableScreenshotTest=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b3f02bd..a146f40 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -38,6 +38,7 @@ zoomable = "2.6.0" cameraCamera2 = "1.4.2" cameraView = "1.4.2" foundation = "1.8.1" +screenshot = "0.0.1-alpha09" [libraries] accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" } @@ -93,9 +94,11 @@ ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } zoomable = { module = "net.engawapg.lib:zoomable", version.ref = "zoomable" } androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workManager" } +androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot" }