Question

I'm trying to test my activity (HomeActivity) which has repeating animation based on NineOldAndroids lib with Espresso. I turned off system animation as described here, but it doesn't help and I'm getting an error (see below). The only thing that help is to remove animation manually. So question is do I need to manually turn off animations (using BuildConfig seems hassle free) or maybe I'm doing something wrong? Thank you in advance!

 java.lang.RuntimeException: Could not launch intent Intent {
 act=android.intent.action.MAIN flg=0x14000000
 cmp=com.package.en/com.package.ui.HomeActivity } within 45 seconds.
 Perhaps the main thread has not gone idle within a reasonable amount
 of time? There could be an animation or something constantly
 repainting the screen. Or the activity is doing network calls on
 creation? See the threaddump logs. For your reference the last time
 the event queue was idle before your activity launch request was
 1392052899081 and and now the last time the queue went idle was:
 1392052899081. If these numbers are the same your activity might be hogging the event 
 queue.
Was it helpful?

Solution 2

I don't know much about 9olddroids, but for Espresso you should disable animations in order to your tests become reliable, which you probably already did.

So maybe this is the case to increase your app "testability" by adding some code which disable animations. For instance, your activity could have a method to disable animations, like:

 public void disableAnimations() {
     this.mAnimationsEnabled = false;
 }

And before every animation, you check if they're enabled. Once your test begins, you disable your animations:

 public void setUp () {
    super.setUp();
     YourActivity activity = getActivity();
     activity.disableAnimations();
 }

 public void testXYZ() {
     // your test code
 }

I hope this will work, as 9OldDroids will stop interfering with Espresso

OTHER TIPS

Fix for issue:

    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        Intent intent = getIntent();
        if (intent == null) {
            intent = new Intent();
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        setActivityIntent(intent);
    }

    @SuppressLint("NewApi")
    @Override
    public T getActivity() {
        final T activity = super.getActivity();
        activity.overridePendingTransition(0, 0);
        return activity;
    }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top