In my company we do something different, fwiw. We have an abstraction layer over Apollo, which is an interface with some default methods, let's call it
Repository
, and then we have two implementations, a
RealRepository
with an
ApolloClient
that is set up for production, and for testing we have a
FakeRepository
, that also has an
ApolloClient
more apt for testing (in-memory cache only and
Dispatchers.Main.immediate
dispatcher), but it also stores a map of
Class<out Operation<*>>
to
FakeRepository.(Operation<*>) -> Operation.Data
which we use for instrumentation. Here we use data builders to construct different responses in our tests. With this set up, we don't need to write and maintain JSON files, nor having to use a slow mock web server.
Sharing in case it helps others for inspiration.