Scenario:
I'm trying to unit test the onClick handler of my application. Onclick does a simple search against a REST API, returns the results and updates the UI.
Details:
Onclick executes an AsyncTask, the doInBackground queries the REST API and returns the results. The onPostExecute takes the results and assigns a new ListAdapter to the ListView with the data.
Problem:
The onPostExecute doesn't get called in by the Test Runner since it's on the same UI Thread and blocks the call. There are several patterns for dealing with this. However, if I put the AsyncTask in a Runnable and use the LatchCountdown to wait for the result, I get the CalledFromWrongThread Exception.
Is there a good solution to unit testing an AsyncTask that does UI updates? Or a more testable design that I can implement?