下面列出了android.support.test.espresso.Espresso#registerIdlingResources ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void runTest()throws Exception{
ElapsedTimeIdlingResource idlingResource = new ElapsedTimeIdlingResource(1000 * 1);
Espresso.registerIdlingResources(idlingResource);
groupNameTest();
myNameTest();
qrcodeTest();
managerTest();
checkTest();
otherTest();
}
@Before
public void registerIdlingResource() {
List<View> viewList = Arrays.asList(mActivityRule.getActivity()
.findViewById(R.id.textView));
mIdlingResource = new ViewIdlingResource(viewList);
Espresso.registerIdlingResources(mIdlingResource);
}
@Before
public void registerIdlingResource() {
PhilHackerNewsApplication application = (PhilHackerNewsApplication) mActivityTestRule.getActivity().getApplication();
application.getObjectGraph().inject(this);
mSyncAdapterIdlingResource = new SyncAdapterIdlingResource(mDataSynchronizer);
Espresso.registerIdlingResources(mSyncAdapterIdlingResource);
}
@Before
public void setup() {
Espresso.registerIdlingResources(EspressoIdlingResource.getIdlingResource());
mainActivityActivityTestRule.launchActivity(null);
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
MainActivity mainActivity = mainActivityActivityTestRule.getActivity();
instrumentation.runOnMainSync(() -> {
Flow.get(mainActivity.getBaseContext()).setHistory(History.single(LoginKey.create()), Direction.REPLACE);
});
ServiceProvider serviceProvider = ServiceProvider.get(mainActivity.getBaseContext());
LoginComponent loginComponent = serviceProvider.getService(LoginKey.create(), DaggerService.TAG);
loginPresenter = loginComponent.loginPresenter();
}
@Before
public void setup() {
Espresso.registerIdlingResources(EspressoIdlingResource.getIdlingResource());
mainPage = new MainPage();
repositoriesPage = new RepositoriesPage();
mainActivityActivityTestRule.launchActivity(null);
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
MainActivity mainActivity = mainActivityActivityTestRule.getActivity();
instrumentation.runOnMainSync(() -> {
Flow.get(mainActivity.getBaseContext()).setHistory(History.single(RepositoriesKey.create()), Direction.REPLACE);
});
}
@Test
public void testEspressoWay() throws Exception {
// Instantiate and register the IdlingResource
CappuccinoIdlingResource idlingResource = new CappuccinoIdlingResource(mActivityTestRule.getActivity());
Espresso.registerIdlingResources(idlingResource);
// This view animates in
onView(withId(R.id.text_hello)).check(matches(isDisplayed()));
// Unregister the IdlingResource
Espresso.unregisterIdlingResources(idlingResource);
}
@Override
public final void perform(UiController uiController, View view) {
final StepperLayout stepperLayout = (StepperLayout) view;
final ViewPager viewPager = (ViewPager) stepperLayout.findViewById(com.stepstone.stepper.R.id.ms_stepPager);
// Add a custom tracker listener
final CustomViewPagerListener customListener = new CustomViewPagerListener();
viewPager.addOnPageChangeListener(customListener);
// Note that we're running the following block in a try-finally construct. This
// is needed since some of the actions are going to throw (expected) exceptions. If that
// happens, we still need to clean up after ourselves to leave the system (Espresso) in a good
// state.
try {
// Register our listener as idling resource so that Espresso waits until the
// wrapped action results in the view pager getting to the STATE_IDLE state
Espresso.registerIdlingResources(customListener);
uiController.loopMainThreadUntilIdle();
performAction(stepperLayout);
uiController.loopMainThreadUntilIdle();
customListener.mNeedsIdle = true;
uiController.loopMainThreadUntilIdle();
customListener.mNeedsIdle = false;
} finally {
// Unregister our idling resource
Espresso.unregisterIdlingResources(customListener);
// And remove our tracker listener from ViewPager
viewPager.removeOnPageChangeListener(customListener);
}
}
@Before
public void setUp() throws Exception {
editText = activityRule.getActivity().editText;
TestActivity activity = activityRule.getActivity();
viewDirtyIdler = new ViewDirtyIdlingResource(activity);
Espresso.registerIdlingResources(viewDirtyIdler);
}
@Override
public void onCreate(Bundle arguments) {
super.onCreate(arguments);
RxIdlingResource rxIdlingResource = new RxIdlingResource();
RxJavaPlugins.getInstance()
.registerObservableExecutionHook(new RxIdlingExecutionHook(rxIdlingResource));
Espresso.registerIdlingResources(rxIdlingResource);
}
@Before
public void registerIdlingResource() {
mIdlingResource = mActivityRule.getActivity().getIdlingResource();
// To prove that the test fails, omit this call:
Espresso.registerIdlingResources(mIdlingResource);
}
@Before
public void setUp() {
idlingResource =
OkHttp3IdlingResource.create("OkHttp", InjectionFactory.okHttpClient);
Espresso.registerIdlingResources(idlingResource);
}
/** Register idling resources don't stop flow when junit asserts is used **/
public void registerIdlingResource() {
Espresso.registerIdlingResources(this);
}
@Before
public void registerIdlingResource() {
mIdlingResource = newThreadPoolIdlingResource(CalculatorExecutor.EXECUTOR, "resultRepo");
Espresso.registerIdlingResources(mIdlingResource);
}
@Before
public void before() {
Espresso.registerIdlingResources(mBottomSheetIdlingResource);
Intent dummyIntent = new Intent(DUMMY_ACTION);
mStubbedEmptyViewActionPendingIntent = PendingIntent.getBroadcast(InstrumentationRegistry.getTargetContext(), TEST_REQUEST_CODE, dummyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@NonNull
public static IdlingResource timeout(long waitTimeMs) {
IdlingResource idlingResource = new TimeIdlingResource(waitTimeMs);
Espresso.registerIdlingResources(idlingResource);
return idlingResource;
}
/**
* Convenience method for {@link Espresso#registerIdlingResources(android.support.test.espresso.IdlingResource...)
* Espresso#registerIdlingResources(IdlingResource...)}, which first instantiates an {@link CappuccinoIdlingResource},
* then registers it with {@code Espresso}.
*
* @param name The name from which to generate an {@code CappuccinoIdlingResource}.
* @throws CappuccinoException if there is no {@code CappuccinoResourceWatcher} associated
* with the given {@param name}.
*/
public static void registerIdlingResource(@NonNull String name) {
throwIfAbsent(name);
CappuccinoIdlingResource idlingResource = new CappuccinoIdlingResource(name);
mIdlingResourceRegistry.put(name, idlingResource);
Espresso.registerIdlingResources(idlingResource);
}
/**
* Prepare your test fixture for this test. In this case we register an IdlingResources with
* Espresso. IdlingResource resource is a great way to tell Espresso when your app is in an
* idle state. This helps Espresso to synchronize your test actions, which makes tests significantly
* more reliable.
*/
@Before
public void registerIdlingResource() {
Espresso.registerIdlingResources(
mAddNoteIntentsTestRule.getActivity().getCountingIdlingResource());
}
/**
* Convenience method to register an IdlingResources with Espresso. IdlingResource resource is
* a great way to tell Espresso when your app is in an idle state. This helps Espresso to
* synchronize your test actions, which makes tests significantly more reliable.
*/
private void registerIdlingResource() {
Espresso.registerIdlingResources(
mNoteDetailActivityTestRule.getActivity().getCountingIdlingResource());
}
/**
* Prepare your test fixture for this test. In this case we register an IdlingResources with
* Espresso. IdlingResource resource is a great way to tell Espresso when your app is in an
* idle state. This helps Espresso to synchronize your test actions, which makes tests significantly
* more reliable.
*/
@Before
public void registerIdlingResource() {
Espresso.registerIdlingResources(MyApplication.getInstance().getCountingIdlingResource());
}
/**
* Prepare your test fixture for this test. In this case we register an IdlingResources with
* Espresso. IdlingResource resource is a great way to tell Espresso when your app is in an
* idle state. This helps Espresso to synchronize your test actions, which makes tests significantly
* more reliable.
*/
@Before
public void registerIdlingResource() {
Espresso.registerIdlingResources(MyApplication.getInstance().getCountingIdlingResource());
// SettingsMy.setActualShop(null); USE this and look how to start activity with different intent.
}