简体   繁体   English

Espresso 可以在不有意启动活动的情况下工作吗?

[英]Can Espresso work without launching activity with intent?

I want to write an Espresso test that will use currently launched activity on my tablet's screen.我想编写一个 Espresso 测试,该测试将使用平板电脑屏幕上当前启动的活动。 So I'll manually navigate to this activity with appropriate content prior launching the test, cause it's difficult and reluctant to write additional code to launch this activity with the same global "state" in app and pass all needed params in the launching intent and so one. 因此,我将在启动测试之前手动导航到具有适当内容的此活动, 因为很难且不愿意编写额外的代码以在应用程序中使用相同的全局“状态”启动此活动并在启动意图中传递所有需要的参数等等一。

Is it possible and how to do this with Espresso, or I have to use UI Automator then?是否有可能以及如何使用 Espresso 做到这一点,或者我必须使用 UI Automator 呢?

If you absolutely do not want to set up the intent to launch the activity you want to test then you can just use a breakpoint in your test.如果您绝对不想设置启动要测试的活动的意图,那么您可以在测试中使用断点。 This will allow you to manually navigate to the activity before your Espresso tests start executing.这将允许您在 Espresso 测试开始执行之前手动导航到活动。 I would say, however, that at the very least you should use Espresso to automate those manual steps.然而,我会说,至少你应该使用 Espresso 来自动化这些手动步骤。

@Test
fun testActivityIsDisplayed() {
    openTestActivity() //automate with espresso or put breakpoint to do manually
    onView(withId(R.id.testActivity)).check(matches(isDisplayed()))
}

private fun openTestActivity() {
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM