Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
On github okhttp it is written about the MockWebServer library for testing HTTP requests.
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.
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.
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 questionAsk a Question
731 491 924 answers to any question