/
Launch Graph Manager

Android support


Apollo-Android has support artifacts to help with caching and testing.

SqlNormalizedCacheFactory

Add the following dependency:

apollo-android-support

implementation("com.apollographql.apollo:apollo-android-support:x.y.z")

SqlNormalizedCacheFactory uses the Android framework SQLiteDatabase databse to provide and instance of a NormalizedCacheFactory.

ApolloSqlHelper apolloSqlHelper = ApolloSqlHelper.create(context, "db_name");
NormalizedCacheFactory cacheFactory = new SqlNormalizedCacheFactory(apolloSqlHelper);

ApolloIdlingResource

Add the following dependency:

apollo-idling-resource

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

The Apollo GraphQL client comes with a IdlingResource to use during your Android Espresso UI tests. It needs to be created and registered per ApolloClient instance. Register several IdlingResources with the same name will crash.

  • Example in Java:

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

    // Register the idlingResource before running your tests (once per client).
    val 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.

public final class TestRunner extends AndroidJUnitRunner {
  @Override
  public void onStart() {
    IdlingResource idlingResource = ApolloIdlingResource.create("ApolloIdlingResource", apolloClient);
    IdlingRegistry.getInstance().register(idlingResource);
    // etc...

    super.onStart();
  }
}
Edit on GitHub