如何在Espresso中调用finish()而不是System.exit()

时间:2018-07-28 04:02:11

标签: android android-espresso

我已经在Android Studio 3.1.2中开发了Espresso测试用例。在每个测试用例的结尾,我都有用户会话注销单击和应用程序退出从UI的菜单选项中单击。

点击 Exit (退出)选项可在应用程序中调用 finish() ,但是最近开发人员更改了应用程序并引入了 < em> System.exit(0) 。这在我的Espresso运行中产生了一个新问题(“由于'Process crash',仪器运行失败。。)

现在要避免这种“ 进程崩溃”,我想在我的Espresso代码的末尾引入 finish() 我可以这样做吗?

当前的“注销”和“退出”选项代码:

...
...
       // 3-dots Menu option is displayed which has LOGOUT
        sleep(2700);
        ViewInteraction actionMenuItemView = onView(allOf(withId(R.id.menuLogin),isDisplayed()));
        actionMenuItemView.perform(click());

        // Found LOGOUT now perform a click to end user session
        onData(hasToString("Logout")).inRoot(RootMatchers.isPlatformPopup()).perform(click());

        // 3-dots Menu option is displayed which has EXIT
        sleep(2700);
        ViewInteraction actionMenuItemView2 = onView(allOf(withId(R.id.menuLogin),isDisplayed()));
        actionMenuItemView2.perform(click());

        // Found EXIT now perform a click to exit the application
        onData(hasToString("Exit")).inRoot(RootMatchers.isPlatformPopup()).perform(click());

0 个答案:

没有答案