我有一系列测试幻灯片菜单的Espresso测试。打开“使用主机GPU”时,大多数测试失败,但禁用时则不会失败。即使我已禁用动画,我想我可能会在某个地方错过设置,因为我仍然可以看到窗口滑动打开。我正在测试Android 4.4.2并使用HAXM。为什么这个测试失败了?
这是测试的一个例子(它们都具有相同的结构):
@SuppressWarnings("unchecked")
public void testClickOnItemDisplaysMyFragment() {
openDrawer(DRAWER);
onView(withId(DRAWER)).check(matches(isOpen()));
onView(allOf(withId(DRAWER_ITEM), withText(MY_ITEM))).perform(click());
onView(withId(DRAWER)).check(matches(isClosed()));
Fragment fragment = fragmentManager.findFragmentById(FRAGMENT_LAYOUT);
assertThat(fragment, is(notNullValue()));
assertThat(fragment, is(instanceOf(MyFragment.class)));
onView(withId(fragment.getId())).check(matches(isDisplayed()));
}
如果我在没有选中使用主机GPU的情况下启动我的模拟器,则测试通过正常。如果启用了“使用主机GPU”,则第一次测试通过,然后其余测试通过:
com.google.android.apps.common.testing.ui.espresso.IdlingResourceTimeoutException: Wait for [IdlingDrawerListener] to become idle timed out
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:69)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:159)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.check(ViewInteraction.java:133)
at com.example.MainActivityTest.testClickOnItemDisplaysMyFragment(MainActivityTest.java:152)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
我已尝试在模拟器中禁用动画,如下所述:https://code.google.com/p/android-test-kit/wiki/Espresso#Getting_Started,但我仍然可以看到抽屉滑动打开和关闭。