问题描述
我有一个片段,该片段在加载时应显示一个加载微调框,该微调框消失一次,然后在网络请求完成时填充字段.为了测试,我可以模拟请求.
I have a fragment, which when loaded should display a loading spinner which disappears once then the fields are populated when a network request completes. For testing I can mock the request.
在每种情况下它都非常快,并且您通常不会看到加载"微调器. Espresso是否可以测试该视图首先显示?即使它消失得这么快?
In every case it is very fast and You won't usually see the Loading spinner. Is it possible with Espresso to test that this view is shown first? Even when it disappears so quickly?
我有什么选择来延迟负载足够长的时间以使其可测试? (框架中是否有东西,而不是休眠线程?)
What are my options to delay the load long enough to make it testable? (Is there some thing in the framework, rather than sleeping the thread?)
这是我当前测试的结果:
This is the result of my test currently:
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将等待它们完成,然后再继续测试.
You must disable the loader animations or espresso will wait for them to finish before continuing with the test.
您可以将进度条视图替换为普通视图以进行测试: https://blog.entwicklerbier.org/2015/05/test-your-ui-on-android-with-espresso-damn-you-progressbar/
You can replace the progressbar views with plain views for testing:https://blog.entwicklerbier.org/2015/05/test-your-ui-on-android-with-espresso-damn-you-progressbar/
或者您可以更改进度条的可绘制区域:
Or you can change the progressbar drawable:
ProgressBars和Espresso 或者在具有Espresso的Android上测试进度栏
也许您还应该按照您所说的延迟加载.
And maybe you should also delay the load as you said.
这篇关于使用Espresso在数据之前显示测试加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!