Skip to content

Commit e658ad7

Browse files
authored
Add snippet for screenshot test (#710)
* Add snippet for screenshot test * Apply Spotless --------- Co-authored-by: kul3r4 <820891+kul3r4@users.noreply.github.com>
1 parent 95aeebd commit e658ad7

File tree

4 files changed

+94
-15
lines changed

4 files changed

+94
-15
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
1515
alias(libs.plugins.android.lint) apply false
1616
alias(libs.plugins.spotless) apply false
17+
alias(libs.plugins.roborazzi) apply false
1718
}
1819

1920
allprojects {

gradle/libs.versions.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android-googleid = "1.1.1"
55
androidGradlePlugin = "8.13.0"
66
androidx-activity-compose = "1.11.0"
77
androidx-appcompat = "1.7.0"
8-
androidx-compose-bom = "2025.10.01"
8+
androidx-compose-bom = "2025.11.01"
99
androidx-compose-ui-test = "1.7.0-alpha08"
1010
androidx-compose-ui-test-junit4-accessibility = "1.10.0-beta01"
1111
androidx-constraintlayout = "2.2.1"
@@ -37,8 +37,8 @@ appcompat = "1.7.1"
3737
coil = "2.7.0"
3838
# @keep
3939
compileSdk = "36"
40-
compose-latest = "1.9.4"
41-
composeUiTooling = "1.5.4"
40+
compose-latest = "1.9.5"
41+
composeUiTooling = "1.5.5"
4242
coreSplashscreen = "1.2.0"
4343
coroutines = "1.10.2"
4444
dataStore = "1.1.7"
@@ -76,6 +76,8 @@ protoc = "0.9.5"
7676
protolayout = "1.3.0"
7777
reactive-streams = "1.0.4"
7878
recyclerview = "1.4.0"
79+
robolectric = "4.16"
80+
roborazzi = "1.52.0"
7981
spotless = "8.0.0"
8082
targetSdk = "36"
8183
tiles = "1.5.0"
@@ -84,9 +86,9 @@ validatorPush = "1.0.0-alpha08"
8486
version-catalog-update = "1.0.1"
8587
watchfaceComplicationsDataSourceKtx = "1.2.1"
8688
wear = "1.3.0"
87-
wearComposeFoundation = "1.5.4"
88-
wearComposeMaterial = "1.5.4"
89-
wearComposeMaterial3 = "1.5.4"
89+
wearComposeFoundation = "1.5.5"
90+
wearComposeMaterial = "1.5.5"
91+
wearComposeMaterial3 = "1.5.5"
9092
wearInput = "1.2.0"
9193
wearOngoing = "1.1.0"
9294
wearToolingPreview = "1.0.0"
@@ -209,6 +211,11 @@ hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt"
209211
hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
210212
horologist-compose-layout = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "horologist" }
211213
horologist-compose-material = { module = "com.google.android.horologist:horologist-compose-material", version.ref = "horologist" }
214+
horologist-roboscreenshots = { module = "com.google.android.horologist:horologist-roboscreenshots", version.ref = "horologist" }
215+
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
216+
roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" }
217+
roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" }
218+
roborazzi-rule = { group = "io.github.takahirom.roborazzi", name = "roborazzi-junit-rule", version.ref = "roborazzi" }
212219
jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
213220
junit = { module = "junit:junit", version.ref = "junit" }
214221
kotlin-coroutines-okhttp = { module = "ru.gildor.coroutines:kotlin-coroutines-okhttp", version.ref = "kotlinCoroutinesOkhttp" }
@@ -239,5 +246,6 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
239246
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
240247
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
241248
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
249+
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
242250
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
243251
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }

wear/build.gradle.kts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import org.gradle.internal.classpath.Instrumented.systemProperty
2+
13
plugins {
24
alias(libs.plugins.android.application)
35
alias(libs.plugins.kotlin.android)
46
alias(libs.plugins.compose.compiler)
7+
alias(libs.plugins.roborazzi)
58
}
69

710
android {
@@ -30,11 +33,11 @@ android {
3033
}
3134
}
3235
compileOptions {
33-
sourceCompatibility = JavaVersion.VERSION_17
34-
targetCompatibility = JavaVersion.VERSION_17
36+
sourceCompatibility = JavaVersion.VERSION_21
37+
targetCompatibility = JavaVersion.VERSION_21
3538
}
3639
kotlin {
37-
jvmToolchain(17)
40+
jvmToolchain(21)
3841
}
3942

4043
buildFeatures {
@@ -47,7 +50,13 @@ android {
4750
}
4851
}
4952
kotlinOptions {
50-
jvmTarget = "17"
53+
jvmTarget = "21"
54+
}
55+
56+
testOptions {
57+
unitTests {
58+
isIncludeAndroidResources = true
59+
}
5160
}
5261
}
5362

@@ -89,17 +98,31 @@ dependencies {
8998
implementation(libs.horologist.compose.material)
9099
implementation(libs.androidx.material.icons.core)
91100
implementation(libs.androidx.watchface.complications.data.source.ktx)
101+
implementation(libs.androidx.compose.ui.test.manifest)
92102

93-
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
94-
debugImplementation(libs.androidx.compose.ui.tooling)
95-
debugImplementation(libs.androidx.compose.ui.tooling.preview)
96-
debugImplementation(libs.androidx.compose.ui.test.manifest)
103+
// Testing
104+
testImplementation(libs.androidx.compose.ui.test.junit4)
97105
testImplementation(libs.junit)
106+
testImplementation(libs.robolectric)
107+
testImplementation(libs.roborazzi)
108+
testImplementation(libs.roborazzi.compose)
109+
testImplementation(libs.roborazzi.rule)
110+
testImplementation(libs.horologist.roboscreenshots)
111+
testImplementation(libs.androidx.test.core)
112+
testImplementation(libs.androidx.test.runner)
113+
testImplementation(libs.androidx.compose.ui.test.manifest)
98114

99115
androidTestImplementation(libs.junit)
100116
androidTestImplementation(libs.androidx.test.core)
101117
androidTestImplementation(libs.androidx.test.runner)
102118
androidTestImplementation(libs.androidx.test.espresso.core)
119+
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
103120
androidTestImplementation(libs.androidx.compose.ui.test)
121+
androidTestImplementation(libs.androidx.compose.ui.test.manifest)
122+
123+
debugImplementation(composeBom)
104124
debugImplementation(libs.androidx.compose.ui.tooling)
105-
}
125+
debugImplementation(libs.androidx.compose.ui.tooling.preview)
126+
debugImplementation(libs.androidx.compose.ui.test.manifest)
127+
128+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.wear.snippets.m3.list
18+
19+
import com.google.android.horologist.compose.layout.AppScaffold
20+
import com.google.android.horologist.screenshots.rng.WearDevice
21+
import com.google.android.horologist.screenshots.rng.WearScreenshotTest
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
import org.robolectric.ParameterizedRobolectricTestRunner
25+
26+
// [START android_wear_screenshot_test]
27+
@RunWith(ParameterizedRobolectricTestRunner::class)
28+
class ComposeListScreenTest(
29+
override val device: WearDevice
30+
) : WearScreenshotTest() {
31+
override val tolerance = 0.02f
32+
33+
@Test
34+
fun myScreenTest() =
35+
runTest {
36+
AppScaffold {
37+
ComposeList()
38+
}
39+
}
40+
41+
companion object {
42+
@JvmStatic
43+
@ParameterizedRobolectricTestRunner.Parameters
44+
fun devices() = WearDevice.entries
45+
}
46+
}
47+
// [END android_wear_screenshot_test]

0 commit comments

Comments
 (0)