Giter Club home page Giter Club logo

backpack's Introduction

Backpack

License: MIT

For Data Layer

  • Mock Web Server Extension
  • Resource

Mock Web Server Extension Library

Set of extension functions for testing rest service api interfaces. Having mocked responses into resources folder and reading and passing them into Mock Web Server is hard and lots of boiler plate code must be written to setting it up. These extensions come to help.

Dependency

testImplementation 'io.github.edasich.backpack:data-test-mockwebserver-ext:LATEST_VERSION'

How to use it ?

For instance we have a response file with json format in resources folder, inside of api-response subfolder named sample-200-api-response.json.

Note : Having a subfolder is optional

{
  "title": "This is a sample",
  "description": "Only for test"
}

Then in test method, we can pass the mocked json as file's path into Mock Web Server along with whatever http response code you choose by calling this extension function enqueueResponseFromResourceFile.

    @Test
    fun `test rest service`() =
        runTest {
            val expectedSampleApiResponse = SampleApiResponse(
                title = "This is a sample",
                description = "Only for test"
            )
            // given
            mockWebServerRule.enqueueResponseFromResourceFile(
                absoluteFilePath = "api-response/sample-200-api-response.json",
                code = 200
            )
            // when
            val actualSampleApiResponse = restService.getSample().body()!!
            // then
            MatcherAssert.assertThat(
                actualSampleApiResponse,
                Matchers.`is`(expectedSampleApiResponse)
            )
        }

Also you can create your rest service interface by calling this extension too createRestService.

    @Before
    fun setUp() {
        restService = mockWebServerRule.createRestService(
            converterFactory = GsonConverterFactory.create(),
            serviceClass = SampleRestService::class.java
        )
    }

Resource Library

Reading files from resources folder during test.

Dependency

testImplementation 'io.github.edasich.backpack:data-test-resource:LATEST_VERSION'

How to use it ?

val fileContent: String = "folder/im-the-file-path.json".readFileFromResourceFolder()

backpack's People

Contributors

edasich avatar

Watchers

 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.