I am writing unit tests for Android using the Junit4 syntax through the Android Testing Support Library ( here ). I want to check my custom view. The test involves clicking on the check box and verifying that the value elsewhere gets the update properly, but I get this error when I try to run the test:
android.util.AndroidRuntimeException: Animators may only be run on Looper threads at android.animation.ValueAnimator.start(ValueAnimator.java:1002) at android.animation.ValueAnimator.start(ValueAnimator.java:1050) at android.animation.ObjectAnimator.start(ObjectAnimator.java:829) at android.graphics.drawable.AnimatedStateListDrawable$AnimationDrawableTransition.start(AnimatedStateListDrawable.java:294) at android.graphics.drawable.AnimatedStateListDrawable.selectTransition(AnimatedStateListDrawable.java:226) at android.graphics.drawable.AnimatedStateListDrawable.onStateChange(AnimatedStateListDrawable.java:145) at android.graphics.drawable.Drawable.setState(Drawable.java:599) at android.widget.CompoundButton.drawableStateChanged(CompoundButton.java:438) at android.view.View.refreshDrawableState(View.java:16032) at android.widget.CompoundButton.setChecked(CompoundButton.java:143) at android.widget.CompoundButton.toggle(CompoundButton.java:113)
I don't define any custom animations, and I really don't care about them for this test, but I assume that the Android 5.0 theme creates a checkbox animation.
I assume the exception is thrown because the test does not run in the user interface thread and the animator cannot animate. So how do I run a test on a UI thread?
source share