Docs
Launch GraphOS Studio
You're viewing documentation for a previous version of this software. Switch to the latest stable version.

UI Tests


Apollo Android offers a built-in

to help writing UI tests with Espresso. The ApolloIdlingResource will make sure that your tests wait for your queries terminate before moving on with testing.

Add the following dependency:

apollo-idling-resource

implementation("com.apollographql.apollo:apollo-idling-resource:x.y.z")

If you have multiple ApolloClients you need to create and register multiple ApolloIdlingResource with different names. Registering several IdlingResources with the same name will crash.

// Register the idlingResource before running your tests (once per client).
val idlingResource = ApolloIdlingResource.create("ApolloIdlingResource", apolloClient)
IdlingRegistry.getInstance().register(idlingResource)
// Register the idlingResource before running your tests (once per client).
IdlingResource idlingResource = ApolloIdlingResource.create("ApolloIdlingResource", apolloClient);
IdlingRegistry.getInstance().register(idlingResource);

Most frequently this code is put into a custom TestRunner as below. Please note that you need the ApolloClient instance you use in the app.

class TestRunner : AndroidJUnitRunner() {
override fun onStart() {
val idlingResource = ApolloIdlingResource.create ("ApolloIdlingResource", apolloClient);
IdlingRegistry.getInstance().register(idlingResource);
super.onStart();
}
}
public final class TestRunner extends AndroidJUnitRunner {
@Override
public void onStart() {
IdlingResource idlingResource = ApolloIdlingResource.create("ApolloIdlingResource", apolloClient);
IdlingRegistry.getInstance().register(idlingResource);
// etc...
super.onStart();
}
}
Previous
Gradle configuration options
Next
Custom scalar types
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company