3
PLease我是新來的Android測試,我一直在嘗試修復初始NavigationView測試BU我得到的錯誤。我只是試圖打開抽屜,然後點擊菜單進入新的活動。java.lang.NoSuchMethodError:沒有接口方法onTransitionToIdle()V
java.lang.NoSuchMethodError: No interface method onTransitionToIdle()V in class Landroid/support/test/espresso/IdlingResource$ResourceCallback; or its super classes (declaration of 'android.support.test.espresso.IdlingResource$ResourceCallback' appears in /data/app/com.bellman.inecparrot.mock-2/base.apk)
at android.support.test.espresso.contrib.DrawerActions$IdlingDrawerListener.onDrawerStateChanged(DrawerActions.java:266)
at android.support.v4.widget.DrawerLayout.updateDrawerState(DrawerLayout.java:834)
at android.support.v4.widget.DrawerLayout$ViewDragCallback.onViewDragStateChanged(DrawerLayout.java:2089)
at android.support.v4.widget.ViewDragHelper.setDragState(ViewDragHelper.java:881)
at android.support.v4.widget.ViewDragHelper$2.run(ViewDragHelper.java:338)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:470)
at android.support.test.espresso.base.UiControllerImpl.loopMainThreadUntilIdle(UiControllerImpl.java:365)
at android.support.test.espresso.contrib.DrawerActions$DrawerAction.perform(DrawerActions.java:79)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
下面是我捉迷藏測試:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AppNavigationTests {
/**
* {@link ActivityTestRule} is a JUint {@link Rule @Rule} to launch your activity under test
* <p>
* <p>
* Rules are interceptios which are executed for each test method and are important building
* block for JUnit tests.
*/
@Rule
public ActivityTestRule<HomeActivity> mActivityTestRule =
new ActivityTestRule<>(HomeActivity.class);
private IdlingResource mIdlingResource;
@Test
public void clickOnAndroidHomeIcon_OpensNavigation() {
//check the left drawer is closed at startUp
onView(withId(R.id.drawerlayout))
.check(matches(isClosed(Gravity.LEFT))); //left Drawer should be closed
//open Drawer
onView(withContentDescription(TestUtils.getToolbarNavigationContentDescription(
mActivityTestRule.getActivity(), R.id.toolbar
)))
.perform(click());
//Check if drawer is open by now
onView(withId(R.id.drawerlayout))
.check(matches(isOpen(Gravity.LEFT)));
//close the drawer
onView(withContentDescription(TestUtils.getToolbarNavigationContentDescription(
mActivityTestRule.getActivity(), R.id.toolbar
))).perform(click());
}
@Test
public void clickGovNavigationItem_ShowsGovActivity() {
//open drawer
onView(withId(R.id.drawerlayout))
.check(matches(isClosed(Gravity.LEFT))) //left drawer should be closed
.perform(open());
//start the gov Screen
onView(withId(R.id.navigation_view))
.perform(navigateTo(R.id.action_gov));
//check that the Gov Activity was opened
onView(withId(R.id.gov_frag_frame))
.check(matches(isDisplayed()));
}
}