Error during BDD-Test for Android: java.lang.IllegalStateException: No compose hierarchies found in the app
Asked Answered
D

1

0

I have bdd-test for my app , I use compose and espresso, and I have this error : 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.

This is a part of my code: @WithJunitRule class ComposeRuleHolder {

   companion object {
       lateinit var composeTestRule: ComposeTestRule
   }

   @Rule(order = 0)
   @JvmField
   var composeRule: ComposeTestRule = createEmptyComposeRule()

   @Before
       fun before() {
       composeTestRule = composeRule
     }
}

and after in the class for the test:

fun myPage(func: MyPage.(ComposeTestRule) -> Unit) = MyPage.apply {
    func(
        ComposeRuleHolder.composeTestRule
    )
 }

@OptIn(ExperimentalTestApi::class)
object MyPage { ...
   ....
}

This was working but from about 2 weeks I had this error : Any Idea? Thanks

Dionnadionne answered 28/9, 2023 at 6:59 Comment(0)
L
0

TL;DR Make sure your phone or emulator works fine and it's active, not blocked

it's funny, but in my case the device was blocked. I mean, i'm testing with a physical device, not an emulator, and it entered save power mode and the screen turned off and the phone blocked. So the android studio tries to start the activity and is not able to do so. Make sure your phone or emulator works fine and it's active, not blocked

Lombroso answered 27/6, 2024 at 17:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.