Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does google state that animations should be disabled for UI testing?

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?

like image 216
stoefln Avatar asked Dec 15 '25 07:12

stoefln


1 Answers

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.

like image 51
Prethia Avatar answered Dec 16 '25 23:12

Prethia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!