1
+ /*
2
+ * Copyright 2025 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.compose.snippets.glance
18
+
19
+ import androidx.compose.runtime.Composable
20
+ import androidx.glance.GlanceModifier
21
+ import androidx.glance.appwidget.testing.unit.runGlanceAppWidgetUnitTest
22
+ import androidx.glance.layout.Row
23
+ import androidx.glance.semantics.semantics
24
+ import androidx.glance.semantics.testTag
25
+ import androidx.glance.testing.unit.assertHasText
26
+ import androidx.glance.testing.unit.hasTestTag
27
+ import androidx.glance.text.Text
28
+ import org.junit.Test
29
+
30
+ // [START android_compose_glance_unit_test]
31
+ private const val FAKE_HEADLINE = " EXTRA! EXTRA! READ ALL ABOUT IT!"
32
+
33
+ class MyGlanceComposableTest {
34
+ @Test
35
+ fun myNewsItemComposable_largeSize_hasHeadline () = runGlanceAppWidgetUnitTest {
36
+ // Set the composable to test
37
+ provideComposable {
38
+ MyNewsItemComposable (FAKE_HEADLINE )
39
+ }
40
+
41
+ // Perform assertions
42
+ onNode(hasTestTag(" headline" ))
43
+ .assertHasText(FAKE_HEADLINE )
44
+ }
45
+
46
+
47
+ @Composable
48
+ fun MyNewsItemComposable (headline : String ) {
49
+ Row {
50
+ Text (
51
+ text = headline,
52
+ modifier = GlanceModifier .semantics { testTag = " headline" },
53
+ )
54
+ }
55
+ }
56
+ }
57
+ // [END android_compose_glance_unit_test]
0 commit comments