S
S
slicephp2018-04-07 14:08:46
Java
slicephp, 2018-04-07 14:08:46

How to properly test an Android application?

Given: Models using okhttp internally. How to test this thing?
How to properly test asynchronous applications? unit? Somehow else? Share your experience, comrades.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Carburn, 2018-04-07
@Carburn

On github okhttp it is written about the MockWebServer library for testing HTTP requests.

S
Sergey, 2018-04-08
@red-barbarian

no way. automatic tests can pass 10 times, and stop at 11. You can try to make the architecture such that you can cover your classes with tests as much as possible. leaving asynchrony as the minimum sufficient space in the project. And try to make asynchrony as transparent and understandable as possible.

V
Vladimir Yakushev, 2018-04-12
@VYakushev

Firstly, models should not know at all how you access the Internet: OkHttp, Retrofit, etc.
Second, models don't have to do anything at all. I hope you are talking about business logic classes. Those. about what is now called such words as UseCase or Interactor.
Therefore, to work with the API, you create an Interface that describes the methods and their parameters for interaction. The class that implements this interface is passed to your interactor via a constructor or setter method. But the constructor is better. And inside this class you already have one or another implementation of working with the API. At the same time, your interactor should not know at all how it is and what is implemented. It only has knowledge about the interface of the class.
For the working assembly of the application, you will pass a real class, and for tests, its test implementation: stubs or mocks. And for unit tests, you don't need any internet or mock web servers.

E
elfuegobiz, 2018-04-12
@elfuegobiz

Try robolectric, with it you can test a lot locally with simple unit tests from what is normally tested on the device with instrumental tests, incl. and http.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question