What do you actually want to test?
I'm asking because it seems that you are not clear what you actually want:
- Testing an API? It's the job of the backend to provide a fully working API.
- Testing that your app is doing http communication correctly? That sounds that you want to test Retrofit. But Retrofit is already tested. You can assume that retrofit works and you don't have to test it again.
- Testing that json is parsed correctly? That's already don by jackson or gson that is used internally by Retrofit. Again, there is no need to test that again.
So still the same question: what do you actually want to test on "Model" (business logic layer in MVP)? If retrofit is your whole business logic, than the following things (not already tested by external libraries as mentioned above) can be tested:
- Are your POJO classes annotated correctly so that gson / jackson is deserializing the json received from Github API correctly. How to do that? In that case you need reliable mocked data and can not use live API. In that case you have to mock the server response. Otherwise you can't write a unit test because GithubApi will return different data if you run your test again tomorrow.
- You can test if you handle all http response codes correctly in your app. However, you also have to mock Github API, otherwise you can't simulate that Github API is returning a 404 response, or 401 etc.
So that are the kind of unit tests you can write for a Unit testing the "model" if your model is just retrofit.
I would like that the test actually makes the network connection instead of using a Mock Server.
I hope that you now understand that there is a need of a MockServer.
Otherwise it sounds that you want to write a kind of integration test. But again, what do you actually want to test with that integration test?
To me it seems that you just want to ensure that your app is not crashing when loading data from GithubAPI and scrolling in a list of items in your UI, right?
So such "integration tests" can be written with both Robolectric and Espresso. But, that's actually not a test! do you have any assertEquals()
etc in such a test? So it's a pretty dumb test because you can't verify nothing except that your app is not crashing. If that is what you are looking for, go ahead, write an Espresso test for your activity that loads live data and scrolls your recylcerview all the way down until the end. But you actually have covered pretty nothing with such a test. It's not reliable, reproduceable and only verifies that your app is not crashing in the "happy path". But that's pretty the same as doing it manually when launching the app.
So ask yourself: What do I want to test? What actually should I test? As said, testing retrofit doesn't make sense because it's already tested by square. Testing that scrolling a RecyclerView works doesn't make sense either because the UI widget RecyclerView is already tested internally in the android framework.