DeviceAnimationTestRule

Additional

Language
Java
Version
0.0.2 (Nov 15, 2016)
Created
Oct 22, 2016
Updated
Jan 3, 2017 (Retired)
Owner
Víctor Albertos (VictorAlbertos)
Contributors
Tobias Preuss (johnjohndoe)
Víctor Albertos (VictorAlbertos)
kirillzh
3
Activity
Badge
Generate
Download
Source code
APK file

Commercial

DeviceAnimationTestRule

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.

SetUp

Add to top level gradle.build file

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add to app module gradle.build file

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

Usage

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();

Limitation

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