我必须使用RestAssured和Gpath语法获取userId的最大值。在那之后我不知道该输入什么内容。
我尝试了很多方法,但是没有用。
@BeforeClass
public void setUp() {
endpoint = "https://jsonplaceholder.typicode.com/posts/";
}
public static Response getJsonPath(String endpoint) {
return
when().
get(endpoint).
then().
statusCode(200).
contentType(ContentType.JSON).extract().response();
}
@Test
public void maxUserId() {
Response response = getJsonPath(endpoint)
.then()
.assertThat()
.body();
}
答案 0 :(得分:0)
您可以像这样使用。我尝试过,我得到了10作为最大价值。如果可以,请接受答案
public static void maxUserId() {
int maxValue = getJsonPath(endpoint).jsonPath().get("userId.max()");
System.out.println(maxValue);
}