[英]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.我目前正在使用放心和 Json-unit 针对请求的放心响应断言本地 json 文件。
I currently have a before class method with my base uri.我目前有一个带有我的基本 uri 的类前方法。
I don't know how to make this assertion.我不知道如何做出这种断言。 I'm struggling with the json-unit documentation.
我正在为 json-unit 文档苦苦挣扎。 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:你需要:
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:对于放心的 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.