Android-浓咖啡测试-关闭并应用,然后重新打开吗? [英] Android - Espresso testing - Close and app and then re-open it?

查看:53
本文介绍了Android-浓咖啡测试-关闭并应用,然后重新打开吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的意式浓缩咖啡测试中,我使用"device.pressBack()"关闭了该应用程序. 然后,我想在某个活动中重新打开该应用程序,但是我不确定该怎么做,因为此时我甚至还没有上下文.有人有主意吗?

In my espresso test, I close the app by using "device.pressBack()". I then want to re-open the app, in a certain Activity, but I'm not quite sure how to do that, since I don't even have a context at this point. Does anybody have an idea?

推荐答案

好的,知道了.您可以在测试类中定义一个规则:

OK, got it. You define a rule in your test class:

@Rule
public ActivityTestRule<MyActivity> myActivityTestRule = new ActivityTestRule<>(MyActivity.class, true, false);

然后,在使用device.pressback()之后,可以使用它在应用程序中打开该特定的活动:

Then, after you used device.pressback(), you can use this to open that specific Activity in your app:

myActivityTestRule.launchActivity(null);

这篇关于Android-浓咖啡测试-关闭并应用,然后重新打开吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆