Espresso测试以验证SwipeRefreshLayout是否显示刷新指示器

时间:2018-05-02 07:29:20

标签: android kotlin android-espresso swiperefreshlayout

我想创建一个Espresso测试,用于验证SwipeRefreshLayout是否显示了刷新指示符。我怎么能这样做?

1 个答案:

答案 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()))