Issue
I am writing ui testcases using junit and Espresso in jetpack compose. My Screen consist of Lottie animations and Some Piece of code of Kotlin Courtines.I am writing single test case to check the visibility of button in that screen but it is giving me error that compse Espresso become idle time out.Can any body show some example that how to handle Incrementation and decrementation using espresso in jetpack compose or anyother way to handle this condition....
Solution
So if you are initializing a composeTestRule like this for example:
@get:Rule
val composeTestRule = createEmptyComposeRule()
Then it will suspend until idle when you have composables that are pending layouts, measuring or in some sort of infinite recomposition loop.
Since Compose 1.1, I have noticed that if I have a composable that is composed but not shown on the screen (for example, in an invisible child fragment that has been started), the test will timeout due to the compose idling resource. So my solution was to simply not define a composeTestRule in my test unless the test will be interacting with a visible composable.
If you are interacting directly with the composable, then you can try the following:
composeTestRule.mainClock.autoAdvance = true
Also, perhaps your Lottie animation is causing some sort of infinite recomposition. Try the test without the Lottie animating. You can also try using this to disable animations in your apps build.gradle file:
testOptions {
...
animationsDisabled = true
...
}
If all this still fails, try putting a log in your composable to check if it is recomposing non stop when it shouldn't be, then figure out why it is happening.
Edit: One more thing, you can register your own idling resource for compose (and figure out how that works) using composeTestRule.registerIdlingResource(idlingResource -> compose specific idling resource.)
Answered By - Sean Blahovici
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.