转换 Quarkus 测试的响应主体
Convert response body of a Quarkus Test
我正在尝试测试我的 Quarkus 应用程序。我想检查响应是否大于 0,问题是我调用的端点 return 是字符串而不是数字。如何将响应转换为数字并检查它是否大于 0?
@Test
void getAdminListSize() {
given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.statusCode(200)
.body(greaterThan(0))
;
}
这是我收到的回复:“28357”。
这是我得到的错误:
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: a value greater than <0>
Actual: 28357
只需将正文提取到一个变量中并使用它
@Test
void getAdminListSize() {
String s = given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.assertThat()
.statusCode(200)
.extract()
.body()
.asString();
convert s into a integer and do the assert
}
其他选项是使用 .as(Clazz.class)
并使用你的 dto(如果你有的话)
我正在尝试测试我的 Quarkus 应用程序。我想检查响应是否大于 0,问题是我调用的端点 return 是字符串而不是数字。如何将响应转换为数字并检查它是否大于 0?
@Test
void getAdminListSize() {
given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.statusCode(200)
.body(greaterThan(0))
;
}
这是我收到的回复:“28357”。 这是我得到的错误:
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: a value greater than <0>
Actual: 28357
只需将正文提取到一个变量中并使用它
@Test
void getAdminListSize() {
String s = given()
.when()
.header("Authorization", token_admin)
.get(PATH + "/get?listSize=true")
.then()
.assertThat()
.statusCode(200)
.extract()
.body()
.asString();
convert s into a integer and do the assert
}
其他选项是使用 .as(Clazz.class)
并使用你的 dto(如果你有的话)