简体   繁体   中英

Assert that response body is empty list with rest-assured

How can I check with rest-assured (2.4.0) if the response json is an empty list?

Given the response [] (with header content-type=application/json ) I tried:

.body(Matchers.emptyArray()) // expected: an empty array, actual: []
.body("/", Matchers.emptyArray()) // invalid expression /
.body(".", Matchers.emptyArray()) // invalid expression .

The problem is (probably) that REST Assured returns a List and not an array (and Hamcrest differentiate between the two). You can do:

.body("", Matchers.hasSize(0))

or

.body("$", Matchers.hasSize(0))

or

.body("isEmpty()", Matchers.is(true))

受到@Johan 所说的启发,我尝试了这个,我认为它比其他建议更能告诉读者。

.body("", equalTo(Collections.emptyList()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM