{"id":21363109,"url":"https://github.com/donfuxx/mockinizer","last_synced_at":"2025-07-13T03:31:41.408Z","repository":{"id":87789853,"uuid":"200105212","full_name":"donfuxx/Mockinizer","owner":"donfuxx","description":"An okhttp / retrofit api call mocking library","archived":false,"fork":false,"pushed_at":"2020-06-05T07:27:37.000Z","size":335,"stargazers_count":191,"open_issues_count":4,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-09T13:17:03.259Z","etag":null,"topics":["agile-development","android-library","mock","mock-server","mockwebserver","okhttp3","rest-api","restful-api","retrofit2","testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/donfuxx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-01T19:04:30.000Z","updated_at":"2024-08-04T06:11:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2f75657-1545-4e00-83d0-bf67a2be6a73","html_url":"https://github.com/donfuxx/Mockinizer","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donfuxx%2FMockinizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donfuxx%2FMockinizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donfuxx%2FMockinizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donfuxx%2FMockinizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donfuxx","download_url":"https://codeload.github.com/donfuxx/Mockinizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225850314,"owners_count":17534103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agile-development","android-library","mock","mock-server","mockwebserver","okhttp3","rest-api","restful-api","retrofit2","testing"],"created_at":"2024-11-22T06:17:55.558Z","updated_at":"2025-07-13T03:31:41.395Z","avatar_url":"https://github.com/donfuxx.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mockinizer [![](https://jitpack.io/v/donfuxx/Mockinizer.svg)](https://jitpack.io/#donfuxx/Mockinizer) [![Build Status](https://travis-ci.org/donfuxx/Mockinizer.svg?branch=master)](https://travis-ci.org/donfuxx/Mockinizer)\n\nAn [OkHttpClient](https://github.com/square/okhttp) / [RetroFit](https://github.com/square/retrofit) web api call mocking library that uses Square's [MockWebServer](https://github.com/square/okhttp/tree/master/mockwebserver) to provide mocked responses by using Interceptors.\n\n## What is it?\n\nMockinizer helps Android developers to build apps with web api calls that use OkHttpClient / RetroFit by allowing them to quickly mock some web api responses with MockWebServer. Mockinizer allows to mock only specific api calls, while other api calls will still call the original server. \nThis is particularily usefull in the following scenarios:\n- You are working on a new feature that needs to call new not yet existing apis. With Mockinizer you can quickly swap in the new desired mocked api responses while other api calls will still use the real server\n- You want to test error cases for existing apis. With Mockinizer you can can quickly mock an error 500 response or an 401 Unauthorized for selected api requests and verify if your app handles them gracefully\n- You want to call a mocked api for unit testing and isolate those from the webserver\n\n## Setup\n\n### 1. Add jitpack.io repository: \nAdd jitpack.io repository in **root build.gradle**:\n```gradle\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\n### 2. Add Mockinizer gradle dependency\nAdd the below code in the **app module's build.gradle** (Usually you want to implement it only in debug builds and not release builds) At the time of writing the latest mockinizer_version was 1.1.0, you can get **latest release** version here: https://github.com/donfuxx/Mockinizer/releases\n```gradle\ndependencies {\n    debugImplementation \"com.github.donfuxx:Mockinizer:1.6.0\"\n}\n``` \nYou may also need to add a MockWebServer dependency in your app module:\n```gradle\ndependencies {\n    implementation \"com.squareup.okhttp3:mockwebserver:4.0.1\"\n}\n``` \n\n### 3. Define the RequestFilter / MockResponse Pairs \nThose represent each api call that you want to mock. The **RequestFilter** defines the Request Path (relative to the RetroFit Baseurl) and/or the json body of the request. The **MockResponse** is the desired Response that you want to get returned by your local MockWebServer. See a simple example that defines 2 mock responses where one out of them is an error:\n```Kotlin\npackage com.appham.mockinizer.demo\n\nimport com.appham.mockinizer.RequestFilter\nimport okhttp3.mockwebserver.MockResponse\n\nval mocks: Map\u003cRequestFilter, MockResponse\u003e = mapOf(\n\n    RequestFilter(\"/mocked\") to MockResponse().apply {\n        setResponseCode(200)\n        setBody(\"\"\"{\"title\": \"Banana Mock\"}\"\"\")\n    },\n\n    RequestFilter(\"/mockedError\") to MockResponse().apply {\n        setResponseCode(400)\n    }\n\n)\n```\n\n### 4. Add mockinizer to OkHttpClient\nTo wire up the mocks that you defined in step 3 you just have to call the `mockinize(mocks)` extension function in the OkHttpClient builder and provide the mocks map as the parameter, see example:\n```Kotlin\nOkHttpClient.Builder()\n            .addInterceptor(loggingInterceptor)\n            .mockinize(mocks) // \u003c-- just add this line\n            .build()\n```\nYes, that is it! Just add `.mockinize(mocks)` into the OkHttpClient.Builder chain. Happy mocking! :-)\n\n### 5. Launch app and check logs to verify mocking is working\nOnce you call a mockinized api endpoint in your app then you can verify the mocked responses in the logcat. The attached HttpLogging interceptor should produce logs similar to:\n```\nD/OkHttp: --\u003e GET https://my-json-server.typicode.com/typicode/demo/mockedError\nD/OkHttp: --\u003e END GET\nD/OkHttp: --\u003e GET https://my-json-server.typicode.com/typicode/demo/mocked\nD/OkHttp: --\u003e END GET\nD/OkHttp: --\u003e GET https://my-json-server.typicode.com/typicode/demo/posts\nD/OkHttp: --\u003e END GET\nD/OkHttp: \u003c-- 400 https://localhost:34567/typicode/demo/mockedError (97ms)\nD/OkHttp: content-length: 0\nD/OkHttp: mockinizer: \u003c-- Real request /typicode/demo/mockedError is now mocked to HTTP/1.1 400 Client Error\nD/OkHttp: server: Mockinizer 1.6.0 by Thomas Fuchs-Martin\nD/OkHttp: \u003c-- END HTTP (0-byte body)\nD/OkHttp: \u003c-- 200 https://localhost:34567/typicode/demo/mocked (104ms)\nD/OkHttp: content-length: 98\nD/OkHttp: mockinizer: \u003c-- Real request /typicode/demo/mocked is now mocked to HTTP/1.1 200 OK\nD/OkHttp: server: Mockinizer 1.6.0 by Thomas Fuchs-Martin\nD/OkHttp: [\nD/OkHttp:   {\nD/OkHttp:     \"id\": 555,\nD/OkHttp:     \"title\": \"Banana Mock\"\nD/OkHttp:   },\nD/OkHttp:   {\nD/OkHttp:     \"id\": 675,\nD/OkHttp:     \"title\": \"foooo\"\nD/OkHttp:   }\nD/OkHttp: ]\nD/OkHttp: \u003c-- END HTTP (98-byte body)\nD/OkHttp: \u003c-- 200 https://my-json-server.typicode.com/typicode/demo/posts (1416ms)\nD/OkHttp: date: Sat, 28 Mar 2020 19:11:32 GMT\nD/OkHttp: content-type: application/json; charset=utf-8\nD/OkHttp: set-cookie: __cfduid=de53d4c305959e69c3e8ea1e6b78959001585422691; expires=Mon, 27-Apr-20 19:11:31 GMT; path=/; domain=.typicode.com; HttpOnly; SameSite=Lax\nD/OkHttp: x-powered-by: Express\nD/OkHttp: vary: Origin, Accept-Encoding\nD/OkHttp: access-control-allow-credentials: true\nD/OkHttp: cache-control: no-cache\nD/OkHttp: pragma: no-cache\nD/OkHttp: expires: -1\nD/OkHttp: x-content-type-options: nosniff\nD/OkHttp: etag: W/\"86-YtXc+x6dfp/4aT8kTDdp4oV+9kU\"\nD/OkHttp: via: 1.1 vegur\nD/OkHttp: cf-cache-status: DYNAMIC\nD/OkHttp: expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"\nD/OkHttp: server: cloudflare\nD/OkHttp: cf-ray: 57b3a8502b8a71f7-AMS\nD/OkHttp: [\nD/OkHttp:   {\nD/OkHttp:     \"id\": 1,\nD/OkHttp:     \"title\": \"Post 1\"\nD/OkHttp:   },\nD/OkHttp:   {\nD/OkHttp:     \"id\": 2,\nD/OkHttp:     \"title\": \"Post 2\"\nD/OkHttp:   },\nD/OkHttp:   {\nD/OkHttp:     \"id\": 3,\nD/OkHttp:     \"title\": \"Post 3\"\nD/OkHttp:   }\nD/OkHttp: ]\nD/OkHttp: \u003c-- END HTTP (134-byte body)\n```\nIn above example three api calls have been made. The only api call that wasn´t mocked is the call to https://my-json-server.typicode.com/typicode/demo/posts the other calls to `/mocked` and `/mockedError` got swapped in by Mockinizer! (Notice **localhost** responding to those with the previously defined mock responses)\n\n\n## See Mockinizer Demo Project\nIn case you want to see how it works in action then just check out the [Mockinizer demo project](https://github.com/donfuxx/MockinizerDemo)!\n\n## Run automated tests\nAnother good way to see Mockinizer in action is to run the androidTests: just run `./gradlew build connectedCheck` from the terminal and see in the logcat how api calls got mocked!\n\n## Contributing\nPull requests are welcome! Just [fork Mockinizer](https://github.com/donfuxx/Mockinizer/network/members) and add submit your PR. Also feel free to add issues for new feature requests and discovered bugs. Check the [Contributing guidelines](https://github.com/donfuxx/Mockinizer/blob/master/CONTRIBUTING.md) for more infos.\n\n## Feedback\nIf you like this project then please don't forget to [stargaze Mockinizer](https://github.com/donfuxx/Mockinizer/stargazers) and share it with your friends! \n\n## Stay up to date\nAlways be the first to know about new releases and [add Mockinizer to your watches](https://github.com/donfuxx/Mockinizer/watchers).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonfuxx%2Fmockinizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonfuxx%2Fmockinizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonfuxx%2Fmockinizer/lists"}