单击此按钮时,我有一个按钮,开始 Activity A。
startActivityForResult(Intent(this, A::class.java)
我需要在点击按钮时检查 Espresso 测试,是否开始 Activity A?
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
中:
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.1"
然后,使用 IntentsTestRule
检查您的 Intent 是否已启动:
@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))
}
关于java - 通过单击 View 检查 Espresso 是否启动了新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56405821/