我收到以下异常消息,而实际和预期相同。失败的原因似乎是不正确的。
@Test
public static void Verify()
{
given().
get("http://services.groupkt.com/country/get/all").
then().body("RestResponse.messages", equalTo("[Total [249] records
found.]"));}
FAILED: Verify
java.lang.AssertionError: 1 expectation failed.
JSON path RestResponse.messages doesn't match.
Expected: [Total [249] records found.]
Actual: [Total [249] records found.]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) and much more....
答案 0 :(得分:1)
@Prasad:由于字符串字符我怀疑它。试试这个应该有效的代码
@Test
public void Verify()
{
given()
.get("http://services.groupkt.com/country/get/all")
.then()
.body("RestResponse.messages[0]",equalTo("Total [249] records found."));}
答案 1 :(得分:0)
啊,因为每个人都可以访问您使用过的URL,我可以为您提供此解决方案:
@Test
public void restAssured() {
RestAssured.given()
.accept(ContentType.JSON)
.get("http://services.groupkt.com/country/get/all")
.then()
.statusCode(200)
.body("RestResponse.messages", hasSize(1))
.body("RestResponse.messages[0]", is("Total [249] records found."))
.body("RestResponse.messages", is(Arrays.asList("Total [249] records found.")));
}
注意可能的各种断言: