Reputation: 14556
To avoid flakiness, we highly recommend that you turn off system animations on the virtual or physical devices used for testing.
https://developer.android.com/training/testing/espresso/setup
I do remember that a couple of years ago animations were indeed a problem for my espresso tests. But recently I didn't see any errors introduced because of it.
Does somebody have insight why the stability regards animations has improved but why google is still recommends to disable?
Upvotes: 3
Views: 129
Reputation: 1203
In my experience, testing stuff that contains loading bars/circles etc resulted in AppNotIdleException
What may potentially happen, especially if you don't wrap up your assertions/actions with something that tries it again after X amount of seconds/miliseconds is that, because Junit executes the commands immediately while the animation takes some time to finish, view element you expect to interact with will give an error. (Either because app is in an idle state during animation or simply because view element is not displayed yet)
Also wait mechanisms Google suggest (Idling Resources) and a function in UIController depends on app being in an idle state. I never used idling resources because of it's terrible unmodifiable 5 seconds waiting time before checking if app is idle again but for ui controller
uiController.loopMainThreadForAtLeast(x) // Waits x + more if app is still not idle
While this is not exactly as evil as Thread.sleep(x)
I suspect pausing the application while an animation is going on would crash your tests.
Upvotes: 4