Introduction: A JUnit rule to disable and enable device animations
More: Author   ReportBugs   

Running instrumentation tests on Android using Espresso requires disabling animations. DeviceAnimationTestRule is a JUnit rule which disables device animations prior to running any test, and enable them after every test has been executed.

This solution is just a wrapper around the solution proposed by artem-zinnatullin in his blog entry.


Add to top level file

allprojects {
    repositories {
        maven { url "" }

Add to app module file

dependencies {
    androidTestCompile 'com.github.VictorAlbertos:DeviceAnimationTestRule:0.0.2'


Add to Android manifest the next permission:

<uses-permission android:name="android.permission.SET_ANIMATION_SCALE"/>

Declare DeviceAnimationTestRule as an static field annotated with @ClassRule to your suit:

@ClassRule static public DeviceAnimationTestRule
      deviceAnimationTestRule = new DeviceAnimationTestRule();


As it has been documented in this issue, you need to run your tests on devices upon on API 21.

Support Me
About Me
Google+: Trinea trinea
GitHub: Trinea