通过单击查看是否使用Espresso启动了新的活动 [英] Check if a new Activity is started with Espresso by click on view

查看:73
本文介绍了通过单击查看是否使用Espresso启动了新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击此按钮时,我有一个按钮,开始活动A.

I have a button when click on this, start activity A.

 startActivityForResult(Intent(this, A::class.java)

单击按钮时是否需要进行浓缩咖啡测试,是否开始活动A?

I need to check in an esspresso test when click on the button, start activity A or not?

onView(withId(R.id.button))
       .check(matches(isDisplayed()))
       .check(matches(isEnabled()))
       .perform(click())

        // check is this A Activity start or not?

推荐答案

您可以使用espresso-intents软件包.

首先,尝试将最新版本添加到您的build.gradle:

First, try to add the latest version into your build.gradle:

   androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.1"

然后,使用IntentsTestRule检查您的意图是否已启动:

Then, use IntentsTestRule to check whether your intent is started or not:

    @get:Rule
    val intentRule = IntentsTestRule(MainActivity::class.java)

    @Test
    fun verify_FakeActivity_is_started() {
        onView(withId(R.id.button))
            .check(matches(isDisplayed()))
            .check(matches(isEnabled()))
            .perform(click())

        intended(hasComponent(FakeActivity::class.java.name))
    }

这篇关于通过单击查看是否使用Espresso启动了新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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