Last active
September 21, 2016 08:28
-
-
Save fejd/66d7f5f687020e57eb676caf5f40c39f to your computer and use it in GitHub Desktop.
An example of using @ClassRule to set up the device to disable animations before running Espresso tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of disabling animations and restoring after a suite has finished | |
// SystemAnimations.java -> https://github.com/reark/reark/blob/master/app/src/androidTest/java/io/reark/rxgithubapp/activities/utils/SystemAnimations.java | |
import org.junit.ClassRule; | |
import org.junit.rules.ExternalResource; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Suite; | |
import org.junit.runners.Suite.SuiteClasses; | |
@RunWith(Suite.class) | |
@SuiteClasses({ | |
TestClassA.class, | |
TestClassB.class | |
}; | |
public class EspressoSuite { | |
@ClassRule | |
public static ExternalResource prepareDevice() { | |
return new ExternalResource() { | |
float[] mAnimationScales; | |
@Override | |
protected void before() throws Throwable { | |
super.before(); | |
// Set animations to off before running tests, otherwise test will fail. | |
mAnimationScales = SystemAnimations.disableAll(); | |
} | |
@Override | |
protected void after() { | |
// Tests are done. Reset animation values. | |
if (mAnimationScales != null) { | |
SystemAnimations.enableAll(mAnimationScales); | |
} | |
super.after(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment