Mockfit: A simple way to mock retrofit response in Android
Writing app when api is not implemented yet, has it’s challenges. You may decide to create a fake api server and consume it in your android project.
Or you just instantiate objects with default data to be able to test your UI and functionalities. What if server is down when you have implemented with real api and removed all previous objects?
A nice and clean approach without cumbersome activities mentioned above would be having a mock layer above your network api which will remove boilerplate codes and handle the effort for intercepting between server and your app.
With Mockfit you just define your network response in json files and annotate your api it’s location! if you want to see code checkout the link below:
How does it work
Mockfit is using retrofit library, make sure to add it’s dependency and configure in your project.
Create json file of your api response lets say picsum_list.json
and put it in assets/mock_json
directory
Define your api interface and annotate endpoint with @mock("picsum_list.json")
so that Mockfit can generate config for you
Add MockfitInterceptor
to retrofit configuration
That’s it now you can see your mock data in UI: