Android SwipeRefreshLayout blocks测试中的Espresso RecyclerView
我有回收站Android SwipeRefreshLayout blocks测试中的Espresso RecyclerView,android,android-espresso,Android,Android Espresso,我有回收站 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/dashboard_swiperefreshlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical"> <android.suppo
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/dashboard_swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/events_dashboard_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"/>
</android.support.v4.widget.SwipeRefreshLayout>
但测试因错误而挂起:
Could not launch intent Intent within 45 seconds
如果我手动滚动RecycleView或更改适配器中的可见页面,测试将继续,抽屉将被打开。SwipeRefreshLayout的加载指示器可能会显示,从而阻塞UI,因为它正在制作动画。避免显示动画的布局的快速修复方法是使用如下内容:
class TestableSwipeRefreshLayout : SwipeRefreshLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
companion object {
var isTestRunning = false
}
override fun setRefreshing(refreshing: Boolean) {
if (!isTestRunning) {
super.setRefreshing(refreshing)
}
}
}
可能会显示SwipeRefreshLayout的加载指示器,从而阻止UI,因为它正在制作动画。避免显示动画的布局的快速修复方法是使用如下内容:
class TestableSwipeRefreshLayout : SwipeRefreshLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
companion object {
var isTestRunning = false
}
override fun setRefreshing(refreshing: Boolean) {
if (!isTestRunning) {
super.setRefreshing(refreshing)
}
}
}