繁体   English   中英

使用 Json 单元断言 Rest Assured 响应

[英]Asserting Rest Assured response with Json Unit

我目前正在使用放心和 Json-unit 针对请求的放心响应断言本地 json 文件。

我目前有一个带有我的基本 uri 的类前方法。

我不知道如何做出这种断言。 我正在为 json-unit 文档苦苦挣扎。 我需要先输入一个文件吗?

    @Test
    public void ApiaryTest1() throws Exception {

        when()

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

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

你需要:

  • 使用 JsonUnit API 读入资源
  • 将响应从放心提取到变量
  • 断言你已经在做

示例:

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

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

对于放心的 Kotlin DSL:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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