PLease我是Android测试的新手,我正在尝试修复初始的NavigationView测试,但我收到错误。我只是想打开抽屉并点击菜单进入新活动。
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()));
}
}
答案 0 :(得分:1)
听起来ProGuard正在删除其中一个所需的接口。我认为您需要在Proguard配置中添加如下所示的行:
-keep public interface android.support.test.espresso.IdlingResource $ ResourceCallback {*;}
我目前没有办法测试它,所以如果这不是很正确而你需要调整它,这里有一个链接到Proguard手册的“保持”选项: http://proguard.sourceforge.net/manual/usage.html#keepoverview