📌  相关文章
📜  您如何验证响应正文中的值? - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:11.345000             🧑  作者: Mango

代码示例1
● For exp: verify ID contains correct number
o Hamster Matcher is assertion library.
then().assertThat().body(“Id”,Matchers.equalTo(123));
o Parse into JsonPath and use getInt(), getList(), getString() methods to read Id value. 
And, I can use JUnit Assertion:
String body = ...thenReturn().body().asString(); 
JsonPath json = new JsonPath(body); 
assertEquals(123,json.getInt(“Id”));
o De-serialize into a (POJO) object (or Object Mapping)
POJO myPojo = … when().post(url).thenReturn().body().as(Pojo.class); 
assertEquals(123,myPojo.getId( ) );
And, I can use JUnit Assertion