简体   繁体   中英

Asserting Rest Assured response with Json Unit

I'm currently using rest assured and Json-unit to assert a local json file against the requested rest assured response.

I currently have a before class method with my base uri.

I don't know how to make this assertion. I'm struggling with the json-unit documentation. Do I need to input a file first?

    @Test
    public void ApiaryTest1() throws Exception {

        when()

                .get("/test")
                .then()
                .statusCode(200);

        // compares two JSON documents
        assertJsonEquals("expected/test.json", "http://apiary/test");
        }

You need to:

  • Read in the resource with the JsonUnit API
  • Extract the response from rest assured to a variable
  • Assert you are already doing

Example:

Response response = when().get("<url>");
        response
                .then()
                .statusCode(200);

        // compares two JSON documents
        assertJsonEquals(resource("resource-inside-resources-folder.json"), response.asString());

For Restassured Kotlin DSL:

        When {
            get("http://nowjidev1vm01.ath.bskyb.com/calskyplussearch/health")
        } Then {
            statusCode(200)
        } Extract {
            assertJsonEquals(expectedBody, response().asString())
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM