使用 Espresso 在数据之前显示测试加载器

Test loader displayed before data with Espresso

我有一个片段,加载时应显示一个加载微调器,该微调器会消失一次,然后在网络请求完成时填充这些字段。为了测试,我可以模拟请求。

在任何情况下它都非常快,您通常不会看到加载微调器。 Espresso 是否可以测试首先显示此视图?即使它消失得如此之快?

我有什么选择可以延迟加载足够长的时间以使其可测试? (框架中有什么东西,而不是让线程休眠吗?)

这是我目前的测试结果:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "AppCompatImageView{id=2131624534, res-name=loading_spinner, visibility=GONE, width=126, height=126, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=477.0, y=383.0}"

您必须禁用加载程序动画,否则 espresso 将等待它们完成后再继续测试。

您可以将进度条视图替换为普通视图以进行测试: https://blog.entwicklerbier.org/2015/05/test-your-ui-on-android-with-espresso-damn-you-progressbar/

或者您可以更改可绘制的进度条:

ProgressBars and Espresso 要么

也许你也应该像你说的那样延迟加载。