@Test public void moreReliableAsyncTest() { IdlingResource idleWild= OkHttp3IdlingResource.create("okhttp3", main.getActivity().getOkHttpClient()); IdlingRegistry.getInstance().register(idleWild); try { onView(withId(android.R.id.list)) .check(new AdapterCountAssertion(100)); } finally { IdlingRegistry.getInstance().unregister(idleWild); } }
@Test public void adapterHasData() throws InterruptedException { // //Arrange // //Register Rx Idling (Only needed for specific tests that need to wait for data) RxEspressoHandler rxEspressoHandler = new RxEspressoHandler(); RxJavaPlugins.setScheduleHandler(rxEspressoHandler.getRxEspressoScheduleHandler()); RxJavaPlugins.setOnObservableAssembly(rxEspressoHandler.getRxEspressoObserverHandler()); IdlingRegistry.getInstance().register(rxEspressoHandler.getIdlingResource()); // //Act // activityTestRule.launchActivity(new Intent()); // //Assert // onView(withId(R.id.recyclerView)).check(new RecyclerViewItemCountAssertion(20)); }
@After public void tearDown() { //Note - you must remove the idling resources after each Test Collection<IdlingResource> idlingResourceCollection = IdlingRegistry.getInstance().getResources(); for (IdlingResource idlingResource : idlingResourceCollection) { IdlingRegistry.getInstance().unregister(idlingResource); } }
@After public void tearDown() throws Exception { if ( loaderIdlingResource != null ) IdlingRegistry.getInstance().unregister(loaderIdlingResource); applicationHandler.reset(); playerHandler.reset(); Context context = activityTestRule.getActivity(); Database.flush(context.getContentResolver(), hostInfo); Utils.enableAnimations(context); }
@Before public void setUp() throws Throwable { activityTestRule = getActivityTestRule(); final Context context = activityTestRule.getActivity(); if (context == null) throw new RuntimeException("Could not get context. Maybe activity failed to start?"); Utils.clearSharedPreferences(context); //Prevent drawer from opening when we start a new activity Utils.setLearnedAboutDrawerPreference(context, true); //Allow each test to change the shared preferences setSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean useEventServer = prefs.getBoolean(HostFragmentManualConfiguration.HOST_USE_EVENT_SERVER, false); hostInfo = Database.addHost(context, server.getHostName(), HostConnection.PROTOCOL_TCP, HostInfo.DEFAULT_HTTP_PORT, server.getPort(), useEventServer, kodiMajorVersion); //Allow each test to change the host info configureHostInfo(hostInfo); loaderIdlingResource = new LoaderIdlingResource(activityTestRule.getActivity().getSupportLoaderManager()); IdlingRegistry.getInstance().register(loaderIdlingResource); Utils.disableAnimations(context); Utils.setupMediaProvider(context); Database.fill(hostInfo, context, context.getContentResolver()); Utils.switchHost(context, activityTestRule.getActivity(), hostInfo); //Relaunch the activity for the changes (Host selection, preference changes, and database fill) to take effect activityTestRule.finishActivity(); activityTestRule.launchActivity(new Intent()); }
allOf(withId(R.id.textState))); IdlingRegistry.getInstance().register(downloadCompleteIdlingResource); Log.e(TAG,"textView.check COMPLETED"); textView.check(matches(withText("COMPLETED"))); Log.e(TAG,"unregister(downloadCompleteIdlingResource)"); IdlingRegistry.getInstance().unregister(downloadCompleteIdlingResource); Log.e(TAG,"finished");
IdlingRegistry.getInstance().register(rxEspressoHandler.getIdlingResource());
allOf(withId(R.id.textState))); IdlingRegistry.getInstance().register(downloadCompleteIdlingResource); Log.e(TAG,"textView.check COMPLETED"); textView.check(matches(withText("COMPLETED"))); Log.e(TAG,"unregister(downloadCompleteIdlingResource)"); IdlingRegistry.getInstance().unregister(downloadCompleteIdlingResource); Log.e(TAG,"finished");
RxJavaPlugins.setScheduleHandler(rxEspressoHandler.getRxEspressoScheduleHandler()); RxJavaPlugins.setOnObservableAssembly(rxEspressoHandler.getRxEspressoObserverHandler()); IdlingRegistry.getInstance().register(rxEspressoHandler.getIdlingResource()); IdlingRegistry.getInstance().unregister(rxEspressoHandler.getIdlingResource());