Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL Federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free
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 IdlingResource 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
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc., d/b/a Apollo GraphQL.

Privacy Policy

Company