epsilones
epsilones

Reputation: 11609

Espresso test outputs in timeout

I am doing usual test such as :

runTestOnUiThread(new Runnable() {
            @Override
            public void run() {
                some_button.performClick();
               onView(withId(R.id.some_other_button)).check(matches(isDisplayed()));

            }
        });
}

But the test never ends. Now if I take onView method and if I put it after the runTestOnUiThread statement, then the result is the same. Someone has an idea ?

Upvotes: 3

Views: 5188

Answers (1)

thaussma
thaussma

Reputation: 9876

That's not usual what you are doing. You are calling onView() on the UI thread of the application under test, that's why the test never ends. It's a plain old deadlock.

To make the test end, do not call Espresso methods in runTestOnUiThread. And in UI tests you shouldn't click on Buttons by calling the performClick() method either. Use Espresso for that:

public void test_click(){
    // Click on the `some_button`
    onView(withId(R.id.some_other)).perform(click());

    // Or click on view with the text 'OK`
    onView(withText("OK")).perform(click());

    // Check that a view with R.id.some_other_button is displayed
    onView(withId(R.id.some_other_button)).check(matches(isDisplayed()));
}

The AppNotIdleException is thrown when Espresso has to wait too long for the app to become idle. In your case the app is doing something in the background with AsyncTasks. Do you have some tasks running?

To reduce time until Espresso fails, you can reduce its timeouts:

@BeforeClass
public static void beforeClass() {
    IdlingPolicies.setMasterPolicyTimeout(10, TimeUnit.SECONDS);
    IdlingPolicies.setIdlingResourceTimeout(10, TimeUnit.SECONDS);
}

Upvotes: 2

Related Questions