你可以用
espresso-intents
包裹。
首先,尝试将最新版本添加到
build.gradle
:
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.1"
然后,使用
IntentsTestRule
@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))
}