Apollo Kotlin provides a built-in
IdlingResource to help you write UI tests with Espresso. The
ApolloIdlingResource makes sure that your tests wait for your GraphQL queries to terminate before proceeding.
If you have multiple
ApolloClients, you need to create and register a different
ApolloIdlingResource with a different name for each. Registering multiple
IdlingResources with the same name will cause your test suite to crash.
// Create your IdlingResourceval idlingResource = ApolloIdlingResource("apolloIdlingResource")// Register the idlingResource before running your tests (once per client).IdlingRegistry.getInstance().register(idlingResource)// Intruct your ApolloClient to update the IdlingResourceval apolloClient = ApolloClient.Builder().serverUrl("https://example.com/graphql").idlingResource(idlingResource).build()
In the example above, all operations executed by
apolloClient (except subscriptions, which might run for a long time) will update the
IdlingResource so that no automatic actions take place while your app is waiting for data.