简体   繁体   中英

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. 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?

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. I would say, however, that at the very least you should use Espresso to automate those manual steps.

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

private fun openTestActivity() {
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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