How do folks "mock" their apollo service? For exam...
# apollo-kotlin
c
How do folks "mock" their apollo service? For example, I know retrofit has a mocking artifact. I guess since apollo uses okhttp I can just use a mock okhttp server too here and that should work? (or maybe actually i can use mock okhttp server no matter what client is actually in use 🤔 ) but yeah. how are you mocking this sort of stuff out? ideally i guess itd be nice to have some json files that match up to deterministic resopnses and just read from those files when a proper query is hit.
m
OkHttp mockserver is great, we use it indirectly in all the apollo-kotlin integration tests
There's a apollo-mockserver artifact that is KMP and delegates to OkHttp mockserver for JVM
c
Oh interesting. So apollo-mockserver just delegates to okhttp mockserver. Cool! thanks Martin!
m
If you're only Android/JVM, you might as well use okhttp mockwebserver, you'll have more APIs available
e
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.
c
We actually do the same thing already,but i wanted to know if anyone else did anything more interesting