6

I have a JSON response:

["alice", "jason", "steve", "alex"]

then when use rest assured to test:

when().
       get("/names").
then().
       body(containsInAnyOrder("alice","jason","steve","alex"));

This is not working as I expected, it gives an error:

Expected: iterable over ["alice", "jason", "steve", "alex"] in any order
  Actual: ["alice", "jason", "steve", "alex"]

Also tried with:

when().
       get("/names").
then().
       body(hasItems("alice","jason","steve","alex"));

also not working.

How can I verify a simple JSON array in the response?

1 Answer 1

5

To save any clicking, you have to supply a redundant string to the body method call:

when().
   get("/names").
then().
   body("", hasItems("alice","jason","steve","alex"));

Additionally, even if you only have one item in your array, you still have to use hasItems rather than hasItem. For example:

when().
   get("/names").
then().
   body("", hasItems("alice"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.