Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android + Espresso + async HTTP request -> how to test?

i'm trying to test Android app using Espresso FW and I stucked on the problem with doing async HTTP request.

How can i test the case that app (activity) is waiting for processing request and after the response is received is displayed next activity with result or error message?

I tried to find any solution how to do it in the Espresso with testing against the data from the test server, but without luck.

Many thanks for any advice, example or link.

like image 746
redrom Avatar asked Aug 20 '15 13:08

redrom


People also ask

How do you assert Espresso?

The most used assertion is the matches() assertion. It uses a ViewMatcher object to assert the state of the currently selected view. onView(...). check(matches(withText("Hello!")))


1 Answers

I struggled with this for a few days. If your app is using retrofit to handle HTTP requests, you can add this one line:

.setExecutors(AsyncTask.THREAD_POOL_EXECUTOR, new MainThreadExecutor())

to your RestAdaptor.Builder. This moves all of the HTTP requests into the AsyncTasks pool which is then handled by espresso.

I found the original answer here: http://www.michaelevans.org/blog/2015/08/03/using-espresso-for-easy-ui-testing/

like image 52
Bebop_ Avatar answered Sep 22 '22 20:09

Bebop_