本文介绍了测试完成后,为什么Espresso会离开应用程序?如何阻止它这样做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Studio中的androidTest文件夹中,我有以下测试用例:

In Android Studio, in the androidTest folder, I have this test case:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginActivityTest {

    @Rule
    public ActivityTestRule<LoginActivity> activityTestRule =
            new ActivityTestRule<>(LoginActivity.class);

    @Test
    public void teamsListIsSortedAlphabetically() {
        onView(withId(R.id.etEmail)).perform(click(), replaceText("[email protected]")
        );
        onView(withId(R.id.etPassword)).perform(click(), replaceText("asdasd")
        );
        onView(withId(R.id.bLoginSubmit)).perform(click());
    }
}

该应用程序启动LoginActivity,登录,显示下一个活动1-2秒钟,然后退出该活动,将我留在启动器屏幕上.如何使Espresso停留在该屏幕上?

The app launches LoginActivity, logs in, the next activity is shown for 1-2 seconds and then it exits the activity leaving me on the launcher screen. How do I make Espresso stay on that screen?

推荐答案

对不起,但这是不可能的.

Sorry, but it's impossible.

请阅读以下Google参考:自动进行用户界面测试

Please read this Google reference: Automating User Interface Tests

Espresso,Robotium,Calabash和其他UI测试框架是为进行简短的交互测试而设计的.它模拟了用户的特定行为-运行应用程序,执行一些技巧以及(如果成功的话)关闭应用程序.

Espresso, Robotium, Calabash and other UI test frameworks were made for short interaction testing events. It simulates an user's specific behavior - run app, do some tricks and (if successful) than close an app.

当然,Espresso允许您创建自定义的空闲资源,而不是在应用程序中注册.

Of course, Espresso allow you to create custom idling resources and than register it in app.

使测试休眠特定时间的最简单方法是使用方法Thread.sleep(time_in_miliseconds),但是就像我说的那样,这与自动化测试的想法背道而驰.

The simplest way to hibernate a test for a specific amount of time is use method Thread.sleep(time_in_miliseconds), but like I said it's against idea of automated testing.

这篇关于测试完成后,为什么Espresso会离开应用程序?如何阻止它这样做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 15:54