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
).