okhttp-client-mock
A simple OKHttp client mock, using a programmable request interceptor
Import
On your build.gradle
add:
Usage
Create an OkHttp request interceptor and record some rules, for example:
Then add the interceptor to your OkHttpClient client and use it as usual:
Check an example Integration Test with mocked HTTP responses
You can use the following helper classes to provide mock responses from resources:
ClasspathResources.resource
to load content from classpathAndroidResources.asset
to load content from an Android's assetAndroidResources.rawRes
to load content from an Android's raw resourceRoboResources.asset
andRoboResources.rawRes
if you are running Roboelectric tests