sergio-sastre / AndroidUiTestingUtils

A set of TestRules, ActivityScenarios and utils to facilitate UI and screenshot testing under given configurations: FontSizes, Locales...
MIT License
287 stars 14 forks source link

java.lang.IllegalStateException: No compose hierarchies found in the app. #29

Closed sergio-sastre closed 1 year ago

sergio-sastre commented 1 year ago

Describe the bug

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

it happens very often on API 33, have also seen it on API 26 but much rarely.

Environment The setup in which the bug is reproducible:

Expected behavior The test runs normally without throwing an exception

Additional context

  1. Might have to do with the fix on 1.2.2 to run tests on API 33, adding androidTestImplementation("androidx.test:core:1.5.0-beta01")
  2. Might be a compatibility problem between createEmptyComposeRule() and ActivityScenario? Check solution here Another option would be not to use createEmptyComposeRule() at all and use a bitmap for comparing the screenshot instead
sergio-sastre commented 1 year ago

It seems it had to do with previous ActivityScenario not being closed when using an ActivityScenarioForComposableRule

Should be fixed in upcoming 1.2.3