Search in sources :

Example 1 with IdlingResource

use of android.support.test.espresso.IdlingResource in project cw-omnibus by commonsguy.

the class OkHttpTests method moreReliableAsyncTest.

@Test
public void moreReliableAsyncTest() {
    IdlingResource idleWild = OkHttp3IdlingResource.create("okhttp3", main.getActivity().getOkHttpClient());
    Espresso.registerIdlingResources(idleWild);
    try {
        onView(withId(android.R.id.list)).check(new AdapterCountAssertion(100));
    } finally {
        Espresso.unregisterIdlingResources(idleWild);
    }
}
Also used : OkHttp3IdlingResource(com.jakewharton.espresso.OkHttp3IdlingResource) IdlingResource(android.support.test.espresso.IdlingResource) Test(org.junit.Test)

Example 2 with IdlingResource

use of android.support.test.espresso.IdlingResource in project Rosie by Karumi.

the class InjectedInstrumentationTest method tearDown.

@After
public void tearDown() throws Exception {
    List<IdlingResource> idlingResources = getIdlingResources();
    for (IdlingResource resource : idlingResources) {
        unregisterIdlingResources(resource);
    }
    MainApplication application = getApplication();
    application.resetFakeGraph();
}
Also used : IdlingResource(android.support.test.espresso.IdlingResource) MainApplication(com.karumi.rosie.sample.main.MainApplication) After(org.junit.After)

Example 3 with IdlingResource

use of android.support.test.espresso.IdlingResource in project iosched by google.

the class MyScheduleActivityTest method newDataObtained_DataUpdated.

@Test
public void newDataObtained_DataUpdated() {
    IdlingResource idlingResource = null;
    try {
        // Given initial data displayed
        showDay(2);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_BEFORE)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_2)).check(doesNotExist());
        showDay(1);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_AFTER)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_1)).check(doesNotExist());
        // When new data is available
        mStubMyScheduleModel.setMockScheduleDataDay1(MyScheduleMockItems.getItemsForAttendee(1, false, MyScheduleMockItems.SESSION_TITLE_1));
        mStubMyScheduleModel.setMockScheduleDataDay2(MyScheduleMockItems.getItemsForAttendee(2, false, MyScheduleMockItems.SESSION_TITLE_2));
        mStubMyScheduleModel.fireContentObserver();
        // Wait for the ThrottleContentObserver to process the event
        idlingResource = new ThrottleContentObserverIdlingResource(InstrumentationRegistry.getTargetContext());
        Espresso.registerIdlingResources(idlingResource);
        // Then the new data is shown
        onView(withText(MyScheduleMockItems.SESSION_TITLE_1)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_AFTER)).check(doesNotExist());
        showDay(2);
        onView(withText(MyScheduleMockItems.SESSION_TITLE_2)).check(matches(isDisplayed()));
        onView(withText(MyScheduleMockItems.SESSION_TITLE_BEFORE)).check(doesNotExist());
    } finally {
        if (idlingResource != null) {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
Also used : ThrottleContentObserverIdlingResource(com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource) ThrottleContentObserverIdlingResource(com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource) IdlingResource(android.support.test.espresso.IdlingResource) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 4 with IdlingResource

use of android.support.test.espresso.IdlingResource in project dev-summit-architecture-demo by yigit.

the class FeedActivityTest method registerIdlingResource.

@Before
public void registerIdlingResource() {
    mIdlingResource = new IdlingResource() {

        ResourceCallback mResourceCallback;

        @Override
        public String getName() {
            return "RecyclerView";
        }

        @Override
        public boolean isIdleNow() {
            boolean idle = !mCreatedActivity || !getActivity().mBinding.list.hasPendingAdapterUpdates();
            if (idle && mResourceCallback != null) {
                mResourceCallback.onTransitionToIdle();
            }
            return idle;
        }

        @Override
        public void registerIdleTransitionCallback(ResourceCallback callback) {
            mResourceCallback = callback;
        }
    };
    Espresso.registerIdlingResources(mIdlingResource);
}
Also used : IdlingResource(android.support.test.espresso.IdlingResource) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Aggregations

IdlingResource (android.support.test.espresso.IdlingResource)4 Test (org.junit.Test)2 FlakyTest (android.support.test.filters.FlakyTest)1 LargeTest (android.support.test.filters.LargeTest)1 ThrottleContentObserverIdlingResource (com.google.samples.apps.iosched.testutils.ThrottleContentObserverIdlingResource)1 OkHttp3IdlingResource (com.jakewharton.espresso.OkHttp3IdlingResource)1 MainApplication (com.karumi.rosie.sample.main.MainApplication)1 After (org.junit.After)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1