我想创建一个Espresso测试,用于验证SwipeRefreshLayout
是否显示了刷新指示符。我怎么能这样做?
答案 0 :(得分:3)
没有标准的Espresso matcher,但你可以创建一个自定义的:
object SwipeRefreshLayoutMatchers {
@JvmStatic
fun isRefreshing(): Matcher<View> {
return object : BoundedMatcher<View, SwipeRefreshLayout>(
SwipeRefreshLayout::class.java) {
override fun describeTo(description: Description) {
description.appendText("is refreshing")
}
override fun matchesSafely(view: SwipeRefreshLayout): Boolean {
return view.isRefreshing
}
}
}
}
然后你可以像这样使用它:
onView(withId(R.id.swipe_refresh_layout)).check(matches(isRefreshing()))