Java 通过单击查看,检查是否使用浓缩咖啡启动了新活动
我有一个按钮,当点击这个,开始活动aJava 通过单击查看,检查是否使用浓缩咖啡启动了新活动,java,android,testing,kotlin,android-espresso,Java,Android,Testing,Kotlin,Android Espresso,我有一个按钮,当点击这个,开始活动a startActivityForResult(Intent(this, A::class.java) 单击按钮时,我需要签入esspresso测试,是否启动活动A onView(withId(R.id.button)) .check(matches(isDisplayed())) .check(matches(isEnabled())) .perform(click()) // check is
startActivityForResult(Intent(this, A::class.java)
单击按钮时,我需要签入esspresso测试,是否启动活动A
onView(withId(R.id.button))
.check(matches(isDisplayed()))
.check(matches(isEnabled()))
.perform(click())
// check is this A Activity start or not?
您可以使用
意式浓缩咖啡
套餐
首先,尝试将最新版本添加到您的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))
}