如何使用放心验证json数组?

Jak*_*kim 6 rest-assured

我有一个JSON响应:

["alice", "jason", "steve", "alex"]
Run Code Online (Sandbox Code Playgroud)

然后在使用时放心测试:

when().
       get("/names").
then().
       body(containsInAnyOrder("alice","jason","steve","alex"));
Run Code Online (Sandbox Code Playgroud)

这不符合我的预期,它给出了一个错误:

Expected: iterable over ["alice", "jason", "steve", "alex"] in any order
  Actual: ["alice", "jason", "steve", "alex"]
Run Code Online (Sandbox Code Playgroud)

还试过:

when().
       get("/names").
then().
       body(hasItems("alice","jason","steve","alex"));
Run Code Online (Sandbox Code Playgroud)

也不行.

如何在响应中验证简单的JSON数组?

Cla*_*key 5

要保存任何点击,您必须为 body 方法调用提供一个冗余字符串:

when().
   get("/names").
then().
   body("", hasItems("alice","jason","steve","alex"));
Run Code Online (Sandbox Code Playgroud)

此外,即使您的数组中只有一项,您仍然必须使用hasItems而不是hasItem. 例如:

when().
   get("/names").
then().
   body("", hasItems("alice"));
Run Code Online (Sandbox Code Playgroud)