public final class AnimatorTestRule
extends Object implements TestRule

   ↳ androidx.core.animation.AnimatorTestRule

JUnit TestRule that can be used to run Animators without actually waiting for the duration of the animation. This also helps the test to be written in a deterministic manner. Create an instance of AnimatorTestRule and specify it as a ClassRule of the test class. Use advanceTimeBy(long) to advance animators that have been started. Note that advanceTimeBy(long) should be called from the same thread you have used to start the animator.

 public class SampleAnimatorTest {

     public static AnimatorTestRule sAnimatorTestRule = new AnimatorTestRule();

     public void sample() {
         final ValueAnimator animator = ValueAnimator.ofInt(0, 1000);
         assertThat(animator.getAnimatedValue(), is(0));
         assertThat(animator.getAnimatedValue(), is(500));


Public constructors


Public methods

void advanceTimeBy(long timeDelta)

Advances the animation clock by the given amount of delta in milliseconds.

Statement apply(Statement base, Description description)
long getCurrentTime()

Returns the current time in milliseconds tracked by AnimationHandler.

Inherited methods