AndroidTestCase - Asynch calls
I am writing unit tests (AndroidTestCase). The application under test uses some background services to communicate over the web the get information.
To receive notification of events I am interested in开发者_StackOverflow, (like when content has been delivered etc), I register a listener that exposes various methods. In these listener interface methods, I assert certain things to help me validate i am getting appropriate responses.
My problem is that the test methods are finishing prior to the callback occurring and I do not know how to tell the method to "wait" for the callback to happen.
You should use AsyncTask
for all background thread work... it makes life oh-so-much easier.
Then in your onPostExecute()
implementation, which will run on the UI thread once the worker thread is completed, you can run your test methods.
精彩评论