android - 用于验证 SwipeRefreshLayout 是否显示刷新指示器的 Espresso 测试

标签 android kotlin android-espresso swiperefreshlayout

我想创建一个 Espresso 测试来验证 SwipeRefreshLayout 是否显示刷新指示器。我该怎么做?

最佳答案

没有标准的 Espresso 匹配器,但您可以创建一个自定义匹配器:

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

关于android - 用于验证 SwipeRefreshLayout 是否显示刷新指示器的 Espresso 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50129234/

相关文章:

android - 新生成的代码 "This was auto-generated to implement the App Indexing API."是什么?

android - 移动编程

android - 在Android Studio中使用PDF矢量图

android - 对 root 手机上的目录的访问不一致

Android Espresso 执行(点击())不起作用

android - 无法解析com.android.support.test.espresso:espressgit so-core:3.0.1

java - 无法从java调用kotlin扩展函数

android - 如何从 Firebase 中的实时数据库获取数组

Android Jetpack Compose 全宽抽屉

android - 为什么 Espresso 在测试完成后离开应用程序?如何阻止它这样做