我是 Android 开发新手。我想使用 Espresso 来测试我的抽屉是否打开,然后单击一个项目并检查它是否打开了一个新 Activity 。我一直在寻找这方面的例子,但一直没有成功。
最佳答案
@Test
public void clickOnYourNavigationItem_ShowsYourScreen() {
// Open Drawer to click on navigation.
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
.perform(DrawerActions.open()); // Open Drawer
// Start the screen of your activity.
onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.your_navigation_menu_item));
// Check that you Activity was opened.
String expectedNoStatisticsText = InstrumentationRegistry.getTargetContext()
.getString(R.string.no_item_available);
onView(withId(R.id.no_statistics)).check(matches(withText(expectedNoStatisticsText)));
}
这正是您要寻找的。p>
关于Android - 如何使用 Espresso 单击抽屉导航上的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944723/