Android animation scales can make Espresso tests wait for transitions or observe a screen before it has settled. Turning off the device-level window, transition, and animator scales gives UI tests a fixed starting point on emulators and dedicated test devices.
The setting lives in Android's global settings table, so adb shell settings put global can change it without opening Developer options on the device. The three scale keys control window animations, activity transitions, and property animators, and all three need to be disabled for the test environment to behave consistently.
Use this on automation devices, CI emulators, or local test emulators before starting the instrumentation run. A shared physical device will keep the changed animation scales after the test run, so record the previous values before changing it or restore them after testing.
Steps to disable Android animations for Espresso tests:
- Confirm adb sees the target emulator or device.
$ adb devices List of devices attached emulator-5554 device
If more than one device is attached, add adb -s <serial> before each shell settings command.
- Check the current window animation scale.
$ adb shell settings get global window_animation_scale 1.0
- Check the current transition animation scale.
$ adb shell settings get global transition_animation_scale 1.0
- Check the current animator duration scale.
$ adb shell settings get global animator_duration_scale 1.0
Save these values if the same device is also used for manual testing.
- Disable window animations on the target device.
$ adb shell settings put global window_animation_scale 0
- Disable transition animations on the target device.
$ adb shell settings put global transition_animation_scale 0
- Disable animator duration scale on the target device.
$ adb shell settings put global animator_duration_scale 0
- Verify the window animation scale is disabled.
$ adb shell settings get global window_animation_scale 0
- Verify the transition animation scale is disabled.
$ adb shell settings get global transition_animation_scale 0
- Verify the animator duration scale is disabled.
$ adb shell settings get global animator_duration_scale 0
- Run the connected Espresso test task.
$ ./gradlew connectedAndroidTest BUILD SUCCESSFUL in 1m 12s 42 actionable tasks: 6 executed, 36 up-to-date
Android projects with product flavors or build variants may expose a variant-specific task such as connectedDebugAndroidTest.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.