义式浓缩咖啡测试时出现错误
第47行是第二个测试中试图执行单击操作的代码。
第一个测试通过了第二个失败的地方,因为由于异常甚至无法运行。
@LargeTest
@RunWith(AndroidJUnit4::class)
class EntryActivityUITest {
@Rule
@JvmField
val entryAuthActivityRule = ActivityTestRule(EntryActivity::class.java, true, false)
@Test
fun it_should_show_logDetails_buttons_after_starting() {
entryAuthActivityRule.launchActivity(null)
Espresso.onView(ViewMatchers.withId(R.id.auth_button_logDetails))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}
@Test
fun should_open_logDetails_activity_after_pressing_logDetails_button() {
entryAuthActivityRule.launchActivity(null)
val button = entryAuthActivityRule.activity.findViewById<Button>(R.id.auth_button_logDetails)
button.performClick()
Espresso.onView(ViewMatchers.withId(R.id.loginDetails_textEdit_password))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
}
}
这里会发生什么?以及如何解决呢?
最佳答案
那两条线
val button = entryAuthActivityRule.activity.findViewById<Button>(R.id.auth_button_logDetails)
button.performClick()
看起来可疑。我本来希望
Espresso.onView(ViewMatchers.withId(R.id.auth_button_logDetails)).perform(ViewActions.click())