开发者

How do I delay the running of an android test so that an AsyncTask is finished first?

开发者 https://www.devze.com 2023-04-05 23:35 出处:网络
I\'m writing a test for my android app. The app loads in some external data into a view using an AsyncTask.开发者_运维知识库 I want to test that the AsyncTask worked and that the data is properly plac

I'm writing a test for my android app. The app loads in some external data into a view using an AsyncTask.开发者_运维知识库 I want to test that the AsyncTask worked and that the data is properly placed into the view. The problem is that my test is running (and failing) before the AsyncTask is complete.

What's the best way of handling this scenario?


You could use mock data that is returned much faster or implement some sort of waiting/listening for an event in the test.


Create yourself a callback interface which continues your routines after the call returns or use a lock/mutex. I would suggest a callback so you can continue with other tasks while waiting for the data to return e.g. drawing the UI. You could put a loading screen in front to show the user the application is actually waiting for something.

0

精彩评论

暂无评论...
验证码 换一张
取 消