Skip to content
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
2 changes: 2 additions & 0 deletions compose/snippets/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ dependencies {
androidTestImplementation(libs.androidx.compose.ui.test.junit4.accessibility)
debugImplementation(libs.androidx.compose.ui.test.manifest)

androidTestImplementation(libs.androidx.glance.testing)
androidTestImplementation(libs.androidx.glance.appwidget.testing)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.glance

import androidx.compose.runtime.Composable
import androidx.glance.GlanceModifier
import androidx.glance.appwidget.testing.unit.runGlanceAppWidgetUnitTest
import androidx.glance.layout.Row
import androidx.glance.semantics.semantics
import androidx.glance.semantics.testTag
import androidx.glance.testing.unit.assertHasText
import androidx.glance.testing.unit.hasTestTag
import androidx.glance.text.Text
import org.junit.Test

// [START android_compose_glance_unit_test]
private const val FAKE_HEADLINE = "EXTRA! EXTRA! READ ALL ABOUT IT!"

class MyGlanceComposableTest {
@Test
fun myNewsItemComposable_largeSize_hasHeadline() = runGlanceAppWidgetUnitTest {
// Set the composable to test
provideComposable {
MyNewsItemComposable(FAKE_HEADLINE)
}

// Perform assertions
onNode(hasTestTag("headline"))
.assertHasText(FAKE_HEADLINE)
}


@Composable
fun MyNewsItemComposable(headline: String) {
Row {
Text(
text = headline,
modifier = GlanceModifier.semantics { testTag = "headline" },
)
}
}
}
// [END android_compose_glance_unit_test]
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ androidx-emoji2-views = { module = "androidx.emoji2:emoji2-views", version.ref =
androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "androidx-fragment-ktx" }
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance-appwidget" }
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance-appwidget" }
androidx-glance-testing = { group = "androidx.glance", name = "glance-testing", version.ref = "androidx-glance-appwidget" }
androidx-glance-appwidget-testing = { group = "androidx.glance", name = "glance-appwidget-testing", version.ref = "androidx-glance-appwidget" }
androidx-graphics-shapes = "androidx.graphics:graphics-shapes:1.0.1"
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle-runtime-compose" }
Expand Down