如果我想检查视图是否显示,我使用此浓缩咖啡的测试:
@Test
fun toolbar_menu_addTrader_isDisplayed() {
onView(withId(R.id.add_trader))
.check(matches(isDisplayed()))
}
好。
但有时我需要在视图可见时返回 true,否则在不可见时返回 false。
浓缩咖啡可以吗?
我从来没有找到另一个解决方案,所以这是我所做的事情的改编。我相信它符合我的目的:
@Test
fun toolbar_menu_addTrader_isDiplayed() {
// grab a nullable reference to the "add trader" button
val button: ViewInteraction? = onView(withId(R.id.add_trader))
// return whether it is null or not
return button == null
}