/
Launch Apollo Studio

Android support


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

SqlNormalizedCacheFactory

Add the following dependency:

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

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

val apolloSqlHelper = ApolloSqlHelper.create(context, "db_name")
val cacheFactory = 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.

// 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.

class TestRunner : AndroidJUnitRunner() {
    override fun onStart() {
        val idlingResource = ApolloIdlingResource.create ("ApolloIdlingResource", apolloClient);
        IdlingRegistry.getInstance().register(idlingResource);

        super.onStart();
    }
}
Edit on GitHub