How can I make Espresso test continue and NOT wait for an asynctask to complete?

两盒软妹~` 提交于 2020-01-06 06:51:55

问题


In my Android app - after a login there is a static Sync task that can potentially run for a few mins and it pulls data into the phone database.

It's normal that the user can continue to use the app while it syncs down the data. But espresso for some reason it is waiting for the sync AsyncTask to fully finish before going to the next screen, how do I tell Espresso to continue and not wait?

thanks


回答1:


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.



来源:https://stackoverflow.com/questions/51398781/how-can-i-make-espresso-test-continue-and-not-wait-for-an-asynctask-to-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!