Testing ViewPager (and CursorLoader) with Robolectric

I’m not certain, but I would wager that the internal code is trying to use an AsyncTask to invoke the cursor loader’s loadInBackground() method. You might be seeing a deadlock because the AsyncTask tries to invoke onPostExecute(). That call will try to run in your main UI thread, which happens to be the thread of your test routine. That can never happen because you are stuck in a wait with your test routine on the call stack.

Try moving your mocking up to a higher level so that nothing really happens in the background from the test. google `AsyncTask unit test android deadlock’ to see examples where other people ran into similar problems.

Leave a Comment