Android + Espresso + async HTTP request & # 8594; how to test?

I am trying to test an Android application using Espresso FW, and I solved the problem with making an asynchronous HTTP request.

How can I verify that the application (activity) is waiting for a processing request and after receiving a response, the next action is displayed with a result or error message?

I tried to find some solution on how to do this in Espresso with testing data from a test server, but without any luck.

Thanks so much for any advice, example or link.

+6
source share
2 answers

I struggled with this for several days. If your application uses the modification to process HTTP requests, you can add this line:

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

to your RestAdaptor.Builder. This moves all HTTP requests to the AsyncTasks pool, which is then processed by espresso.

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

+1
source

I think the problem is application architecture. You should use some Injection Dependency library to embed a mock service of the mock data service in your application in test mode. When you test mocks when testing. U will avoid network inaccessibility problems or you can simulate network availability according to your test implementation.

0
source

All Articles