It's kinda mind blowing how many different ways I ...
# squarelibraries
c
It's kinda mind blowing how many different ways I can try to have this "mock mode". lol 1. I just learned about this mock retrofit thing which is cool 2. Since retrofit is just an interface, I can just override it and return my own constructed things 3. I just found this inside of okhttp https://github.com/square/okhttp/tree/master/mockwebserver Decisions decisions... I do really like that mockwebserver can literally mock my entire web server. error codes. error bodies. certain weird headers. Sending html instead of json. I know Jake mentioned that he liked the type safety of mock-retrofit, but... mock webserver looks like everything you'd ever want. I do wonder if mockwebserver to implement a fully running mock mode is against the spirit of mockwebserver as it seems to really want to be used inside of tests (from the docs)?
p
Ultimately it comes down to what kind of tests you are trying to write. The MockWebserver serves integration tests very well. It’s great for covering the end-to-end UAT / UI tests. There is a performance hit just because you’re going through the entire networking stack that’s a reasonable price to pay for full integration coverage. On the other hand, if you are looking for blinding fast unit tests and subscribe to the idea that they should isolate the class under test, then the stub / mock version is your best friend. Where on the “test pyramid” do you forsee your tests landing? I think the options are there to give you full choice.
c
Yeah. All good points. I guess in this case, I'm not necessarily writing tests. My "scenario" is that I want to be able to run through my application e2e while I'm developing my app while having no network (working while traveling on a plane for a conference, for example). And while it sounds stupid. I'm seeking advice because I don't want to make some stupid mistake like "Are you crazy? You can't use mockwebserver for what you want to do. You need to use Xyz instead"
e
if that's your use case, maybe you don't need an in-app mock. couldn't you run the server on your laptop and adb forward or reverse tether your phone so your app can access it? (or use the emulator, which already has access to localhost via 10.0.2.2)
c
I'm not in control of my server/source code, so I can't really run the server locally. I have thought of that though.