You are viewing documentation for a previous version of this software.

Switch to the latest stable version.

Testing in Apollo Kotlin

Overview


Apollo Kotlin provides the following tools to help with testing your code:

  • MockServer (experimental): an HTTP server that you can use to mock any responses

  • TestNetworkTransport (experimental): enables you to specify the GraphQL responses returned by ApolloClient

  • Test builders (experimental): help instantiate your model classes by providing a DSL

  • An IdlingResource that you can use in your Espresso UI Tests

MockServer creates a full HTTP server. It requires minimal changes to your production code (you only need to change serverUrl), which means you can use the same ApolloClient for tests and production. MockServer is also useful for testing specific server behaviors, such as error cases, HTTP headers, and timeouts.

TestNetworkTransport bypasses HTTP calls altogether and returns predefined GraphQL responses. It requires more modifications to your production code, but you can use it in lighter tests that don't need to create a server. You can use test builders to instantiate the data in the responses.

Feedback

Edit on GitHub

Forums