Skip to content

A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs. Also includes a cool DSL, that helps to reduce boilerplate code and simplify development.

License

arildojr7/iris-mock

Repository files navigation



ktlint

A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs. Also includes a cool DSL, that helps to reduce boilerplate code and simplify development.

btw, Iris is my daughter's name 🥰

Features

  • Works with Retrofit, Volley and every libs that depend on OkHttp
  • Allow intercept call on 3rd-party libs
  • DSL to avoid boilerplate

Why use iris mock?

  • A centralized tool to log, intercept and modify requests/response
  • As it works at bytecode level, can be used with 3rd-party libs
  • No need to apply KAPT or KSP, since it's implemented directly through KCP
  • No need to do SSL things, like inject certificate

How to use

build.gradle.kts

plugins {
  id("dev.arildo.iris-mock-plugin") version "1.1.0"
}
Using legacy plugin application - older gradle
buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("dev.arildo:iris-mock-plugin:1.1.0-alpha04")
    }
}

apply(plugin = "dev.arildo.iris-mock-plugin")

Code

Just create a class implementing the Interceptor interface and annotate it with @IrisMockInterceptor. That's all. The interceptor will be automatically injected at OkHttp

@IrisMockInterceptor
class MyInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain) = irisMockScope(chain) {
        onGet(contains = "user/profile") mockResponse userProfileJson
        onPost(endsWith = "/login") then {
            delay(2_000) // supports coroutine 
            if (requestContains("validPassword")) mockResponse(successLoginJson)
            else mockResponse(errorPasswordJson)
        }
        enableLogs() // you can log requests
    }
}

See official docs for further details

Roadmap

  • Add support to Ktor
  • Expand DSL
  • and many other cool things

Getting started video

Iris Mock

Contributing

Feel free to open PRs and submit feature suggestions via the repository issues. Everything's welcome 😎

Support

"Buy Me A Coffee"

License

Copyright 2023 Arildo Borges Junior

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs. Also includes a cool DSL, that helps to reduce boilerplate code and simplify development.

Topics

Resources

License

Stars

Watchers

Forks

Languages