问题
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