如何使Espresso测试继续进行,而不等待asynctask完成? [英] How can I make Espresso test continue and NOT wait for an asynctask to complete?

查看:95
本文介绍了如何使Espresso测试继续进行,而不等待asynctask完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中-登录后有一个静态同步任务,该任务可能会运行几分钟,并将数据提取到手机数据库中.

在同步数据时,用户可以继续使用该应用程序是正常的. 但是espresso由于某种原因正在等待同步AsyncTask完全完成,然后再转到下一个屏幕,我如何告诉Espresso继续而不是等待?

谢谢

解决方案

documentation onView()的调用会等到当前没有正在执行任务的AsyncTask实例.不过,请查看 解决方案

As stated in the documentation the call to onView() waits, among the other things, that there are no instances of AsyncTask currently executing a task. Nevertheless, looking at the Espresso implementation, you can note that Espresso looks for an instance of andriod.os.AsyncTask#THREAD_POOL_EXECUTOR (or its support version, android.support.v4.content.ModernAsyncTask). Thus, if you define a custom Executor (try just copying the one from AsyncTask implementation) you can execute the AsyncTask instance this way asyncTask.executeOnExecutor(myCustomExecutor, params) and Espresso won't suspend the onView() calls because an AsyncTask is running.

这篇关于如何使Espresso测试继续进行,而不等待asynctask完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆