小编dlm*_*lmt的帖子

Android Espresso IdlingResources和Fragment/Activity Transitions

我有一个托管片段F1的活动.单击按钮后,F1将被另一个片段F2替换.当按下后退按钮时,应用程序通过退出过渡动画从F2返回到F1 .

我的Espresso测试用例大致如下:

@Test
public void pressingBackRestorePreviousFragment() {
   // we are in F1 and about to switch to F2
   onView(withId(R.id.the_button)).perform(click());

   // we are now in F2, pressing back should "return" to F1
   Espresso.pressBack();

   onView(withText("A specific text in F1")).check(matches(isDisplayed());
}
Run Code Online (Sandbox Code Playgroud)

当测试用例以逐步调试模式运行时,上述测试通过.但在正常运行模式下,它会失败.只有当我Thread.sleep(___)onView(withText(__))测试之前插入才会通过.

我相信更好的技术是替换Thread.sleep()Espresso IdlingResource,但我不确定如何将它与视图动画线程结合.理想情况下,我想重写上面的测试用例

@Test
public void pressingBackRestorePreviousFragment() {
   // we are in F1 and about to switch to F2
   onView(withId(R.id.the_button)).perform(click());

   // we are now in F2, pressing back should …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-espresso android-transitions

2
推荐指数
1
解决办法
1801
查看次数