What are the ways to write unit tests with apollo? As I understand, I can mock responses via MockWebServer and so on. But what if I want to make a local copy of my web-server and make like a real requests? Is it possible?
And can I make a real requests to the real server in unit tests? How can I make it?
You can either to use MockWebServer and enqueue mock http responses or you can add custom implementation of ApolloInterceptor and notify chain with mocked response.
But what if I want to make a local copy of my web-server and make like a real requests? Is it possible?
Not sure what prevents you from specifying local url to GraphQL server that runs locally instead of prod.
And can I make a real requests to the real server in unit tests? How can I make it?
You can not sure what is the issue here? It uses OkHttpClient that easily can run in Unit tests.
Thanks for your thoughts! Eventually I wrote instrumented tests with real calls to test server. Had a problem with awaiting results from server using LiveData in ViewModel...
Found interesting post with LiveData awaiting extension:
http://kotlinblog.com/2017/11/17/testing-room-and-livedata/
@sav007 ,
I have been able to successfully enqueue a mock http response, this is the error I am currently having com.apollographql.apollo.exception.ApolloParseException: Failed to parse http response.
It is unclear what you are doing to cause error. Please take a look at the integration tests which have examples on how to use mock web server with apollo for testing
I am trying to write instrumentation test, I understand that I can mock responses using mockwebserver.
I have been able to successfully enqueue a mock http response, but whenever I run the test, this is the error response I get: com.apollographql.apollo.exception.ApolloParseException: Failed to parse http response.
Happy to help. How can I reproduce?
@phemonick please post full stack trace so we could help you identify the issue.
@mjurkus


@phemonick I suspect that your response is missing "__typename". See example here: https://github.com/apollographql/apollo-android/blob/master/apollo-integration/src/test/resources/HeroAndFriendsNameWithIdsResponse.json
@mjurkus,
Thanks, I will check it out.