Skip to content Skip to sidebar Skip to footer

Check If A New Activity Is Started With Espresso By Click On View

I have a button when click on this, start activity A. startActivityForResult(Intent(this, A::class.java) I need to check in an esspresso test when click on the button, start acti

Solution 1:

You can use espresso-intents package.

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

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

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))
    }

Post a Comment for "Check If A New Activity Is Started With Espresso By Click On View"