One @Rule to disable them all.
Animations. I mean animations.

UI tests are so important that any Android Developer should feel comfortable with setting up the test environment.
Unfortunately, this usually is not the case (and probably an important factor on why people are not writing UI tests). Preparing everything in such a way that it’s easy to write new tests and that tests give repeatable results, can be very overwhelming.
One important thing to figure out is this (from Android Developer docs):

How to automate this process?
I’ve seen few ways people were trying to tackle this problem.
Some of them were unnecessarily complex, other solutions worked… from time to time.
Here’s a super simple test rule you can use to be sure your animations gets disabled before your tests and enabled back on, after tests are finished.
It’s so simple, I’m honestly surprised I haven’t seen anybody else write that before.
It uses just two things: UiAutomator (this means api 18+) and some Android shell commands (executing of which means api 21+). It does exactly what the developer docs are suggesting, executing shell commands… only automatically.
If your project supports older APIs, but you still want to UI test just on 21+, you can still use this rule simply by adding this AndroidManifest.xml
to your androidTest
folder:
The full, easily “includable” version (which already consist of a custom AndroidManifest.xml
) is available here: