https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

05/22/2020, 7:48 AM
How do you test repositories which touch network inside? mockwebserver+json files?
g

gildor

05/22/2020, 8:47 AM
for unit tests fake implementation of API abstraction
🎖️ 1
k

kagomez

05/23/2020, 3:44 PM
you can use #mockk to achieve what @gildor mentioned
g

gildor

05/23/2020, 4:16 PM
Mock/stub/fake depending on how complex API is and what it should do
We use mockwebserver only for integration/instrumentation tests to check whole network pipeline
u

ursus

05/24/2020, 12:14 PM
so you manually write all the ApiFooResponse objects and contents? ughh, I wanted to avoid that
g

gildor

05/24/2020, 2:02 PM
Yes, but how it's different from mocked webserver? Isn't it exactly the same, you have to provide some response data
If you don't want for some reason create object directly, it's also easy to parse some json etc in tests with your test data and return it
u

ursus

05/24/2020, 2:04 PM
well yes that was my original idea, grabbing the response jsons and inject them via mockwebserver
g

gildor

05/24/2020, 4:04 PM
But if you have retrofit you already have interface, which can be replaced with stab implementation, which can return any data to you repository
u

ursus

05/24/2020, 4:05 PM
yes not problem here, I'm just lazy to manually write the response objects which in my stupid api are n-levels deep, 20vals each etc; with jsons I could just grab those from curl and run it through moshi
g

gildor

05/24/2020, 4:15 PM
You can do this in your stab
5 Views