I'm trying to mock a Retrofit setup, specifically ...
# koin
n
I'm trying to mock a Retrofit setup, specifically the response from the OkHttp client. I have the
OkHttpClient
declared as a single dependency, and the Retrofit API as another (which uses
get()
for the client). I found a mock setup for OkHttp that uses an interceptor to return a custom response, but I can't figure out how to set it up with koin. How should I do it? When I use
declareMock
I start getting errors in OkHttp.. When I copy an identical declaration from the
declareMock
to
single
in a non-test environment, everything works exactly as expected. It is only when using the
declareMock
that there is a problem. Here's the difference in object creation order:
Copy code
Mock:
----
Creating client (mock)
Created client (mock)
Creating API wrapper
Creating ProPublica API
Created ProPublica API
Created API wrapper


Real:
----
Creating API wrapper
Creating ProPublica API
Creating client (real)
Created client (real)
Created ProPublica API
Created API wrapper
a
depends on what you want to do
it’s a good idea to have a
mock
version of your OkHttp that returns mocked response
to do that just write a module that will override your client, and will declare this OkHttp object with interceptor
n
That's exactly what I did, but it seems that causes some type of problem with OkHttp
a
you can suggest it via a Github issue