Austyn Mahoney Austyn Mahoney - 6 months ago 61
Android Question

How to test Android UI using IdlingResource when using Retrofit network requests

I am writing integration tests that perform actions in the UI which start network calls using Retrofit.

I know I need to implement a

, but I want to do it the correct way (and not reinvent the wheel if it has already been done).

Has anyone implemented an
in their app's Espresso test suite to wait while network requests execute?

More info here.


The most straightforward solution for this: is to basically swap out Retrofit's Thread-pool executor with an AsyncTask one (as recommended by the very helpful Nick from that linked Google group discussion). I do this like so:

new RestAdapter.Builder()
                             new MainThreadExecutor())

I'm not sure if this is the most appropriate solution, but it's the quickest most sane one that I could get working. Bare in mind the caveat, that this works only for ICS+.