Skip to content

Add a test to introduce compose screenshot testing #4835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ jobs:
with:
category: "Android Lint"

screenshot_test:
runs-on: ubuntu-latest
steps:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the flow diagram on #5158: wouldn't it make more sense to run this after lint/basic build has completed? So needs: [lint, lockfiles, ktlint] like the other tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea grouped next to unit tests maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next to = running at the same time? That's what I was thinking, so basically as 'stage 3'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup let me submit a PR to add that, thanks for the suggestion :)

- uses: actions/checkout@v4

- uses: ./.github/actions/setup-build-env
with:
mock-google-services: "true"

- name: Validate Screenshot Previews
run: ./gradlew validateDebugScreenshotTest

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: Screenshot test results
path: |
**/build/test-results/**/TEST-*.xml

pr_build:
needs: [yamllint, lockfiles]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -278,7 +298,7 @@ jobs:

publish_test_results:
name: "Publish Tests Results"
needs: [instrumentation_test, unit_tests]
needs: [instrumentation_test, unit_tests, screenshot_test]
runs-on: ubuntu-latest
permissions:
checks: write
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ org.gradle.vfs.watch=true
android.defaults.buildfeatures.resvalues=false
android.defaults.buildfeatures.shaders=false
android.nonFinalResIds=false
android.experimental.enableScreenshotTest=true

# Uncomment to disable leak canary
#noLeakCanary=true
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ recyclerview = "1.4.0"
reorderable = "0.9.6"
retrofit = "2.9.0"
room = "2.6.1"
screenshot = "0.0.1-alpha09"
sentry-android = "8.5.0"
timber = "5.0.1"
tools-desugar-jdk-libs = "2.1.5"
Expand Down Expand Up @@ -90,6 +91,7 @@ kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref =
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot" }

# Plugins defined by this project in `:build-logic:convention` module.
homeassistant-android-application = { id = "homeassistant.android.application" }
Expand Down
10 changes: 10 additions & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.homeassistant.android.application)
alias(libs.plugins.google.services)
alias(libs.plugins.screenshot)
}

android {
Expand All @@ -12,6 +13,14 @@ android {
// We add 1 because the app and wear versions need to have different version codes.
versionCode = 1 + checkNotNull(versionCode) { "Did you forget to apply the convention plugin that set the version code?" }
}

experimentalProperties["android.experimental.enableScreenshotTest"] = true

testOptions {
screenshotTests {
imageDifferenceThreshold = 0.00025f // 0.025%
}
}
}

dependencies {
Expand Down Expand Up @@ -66,6 +75,7 @@ dependencies {

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
screenshotTestImplementation(libs.compose.uiTooling)

androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(libs.bundles.androidx.test)
Expand Down
529 changes: 272 additions & 257 deletions wear/gradle.lockfile

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.homeassistant.companion.android

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.wear.tooling.preview.devices.WearDevices
import io.homeassistant.companion.android.common.R
import io.homeassistant.companion.android.home.views.EntityViewList
import io.homeassistant.companion.android.util.previewEntity1
import io.homeassistant.companion.android.util.previewEntity2

class EntityListViewPreviewsTest {

@Preview(device = WearDevices.LARGE_ROUND)
@Composable
private fun PreviewEntityListView() {
EntityViewList(
entityLists = mapOf(stringResource(R.string.lights) to listOf(previewEntity1, previewEntity2)),
entityListsOrder = listOf(stringResource(R.string.lights)),
entityListFilter = { true },
onEntityClicked = { _, _ -> },
onEntityLongClicked = { },
isHapticEnabled = false,
isToastEnabled = false
)
}
}