google-developer-training / basic-android-kotlin-compose-training-tip-calculator

Apache License 2.0
61 stars 93 forks source link

Write automated tests: Android Basics with Compose #151

Closed barnett-yuxiang closed 10 months ago

barnett-yuxiang commented 10 months ago

$ git clone https://github.com/google-developer-training/basic-android-kotlin-compose-training-tip-calculator.git $ cd basic-android-kotlin-compose-training-tip-calculator $ git checkout test_solution

run TipUITests Failed:

java.lang.IllegalStateException: No compose hierarchies found in the app. Possible reasons include: (1) the Activity that calls setContent did not launch; (2) setContent was not called; (3) setContent was called before the ComposeTestRule ran. If setContent is called by the Activity, make sure the Activity is launched after the ComposeTestRule runs at androidx.compose.ui.test.TestContext.getAllSemanticsNodes$ui_test_release(TestOwner.kt:86) at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNodes$ui_test_release(SemanticsNodeInteraction.kt:62) at androidx.compose.ui.test.SemanticsNodeInteraction.fetchOneOrDie(SemanticsNodeInteraction.kt:128) at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNode(SemanticsNodeInteraction.kt:79) at androidx.compose.ui.test.TextActionsKt.getNodeAndFocus(TextActions.kt:108) at androidx.compose.ui.test.TextActionsKt.getNodeAndFocus$default(TextActions.kt:105) at androidx.compose.ui.test.TextActionsKt.performTextInput(TextActions.kt:42) at com.example.tiptime.TipUITests.calculate_20_percent_tip(TipUITests.kt:43)

barnett-yuxiang commented 10 months ago

The device did not light up the screen, so this error was reported 😂

kokage0exe commented 6 months ago

I also faced the same issue, but resolved it for the same reasons :sweat_smile: Thank you!!