Giter VIP home page Giter VIP logo

mockoon-android's Introduction

mockoon-android

Mockoon for Android. More details can be found in this blog post.

This is the android port of mocking server Mockoon. Export your mockoon environment and then run it in android. image

Demo

mockoon-demo

Usage

This library will add around 60MB to your app, so you might want to create a dedicated variant.

Create mock build variant

        mock {
            initWith debug
            applicationIdSuffix ".mock"
        }

Add the depedency

Add this dependency in your app layer's build.gradle.

    mockImplementation 'np.com.susanthapa:mockoon-android:0.6.1'

Start Mockoon

Use reflection to start mockoon as gradle won't be able to resolve the dependency for all variants. Create a helper function to start the server like this.

    private fun startMock(mockPath: String? = null, uri: Uri? = null) {
        if (BuildConfig.BUILD_TYPE == "mock") {
            // use reflection as we don't want to include this in other build variants
            try {
                val mockClass = Class.forName("np.com.susanthapa.mockoon_android.MockoonAndroid")
                val constructor = mockClass.getConstructor(String::class.java, Uri::class.java)
                val mock = constructor.newInstance(mockPath, uri)
                val startMethod = mockClass.getMethod("startMock", Context::class.java)
                startMethod.invoke(mock, this)

            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

The start function accepts two arguments, atleast one argument is required. The first argument mockPath can be used if you have location of the mock file. This is mostly useful when you want to bundle the environment with your app as assets. You can use the second argument uri if you want to load the environment from file systems.

mockoon-android's People

Contributors

susonthapa avatar

Stargazers

Myeong Hoon Lim avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.