A Retrofit Client that reads JSON files from disk and returns them as the response (to be handled by GSON). Make sure the context you pass is from the instrumentation app and put your JSON files in res/raw
in the instrumentation project. Inspired by Ruby's vcr
gem.
A GET
request to /articles
will look for the JSON file res/raw/get_articles.json
, a POST
request to /articles/123/
will look for the JSON file res/raw/post_articles_123.json
, etc.
We use setScenario()
if we want to test alternate responses so that a failed login POST
to /login
will read from res/raw/failed_login_post_login.json
(and the happy path can use post_login.json
).
Other than line 56 and the
.json
references, this could be extend to any data format (e.g. XML), correct? Retrofit will automatically serialize those appropriate if a custom Converter has been set.