[英]Assert that response body is empty list with rest-assured
如果響應 json 是空列表,我如何檢查 rest-assured (2.4.0)?
鑒於響應[]
(帶有標題content-type=application/json
)我試過:
.body(Matchers.emptyArray()) // expected: an empty array, actual: []
.body("/", Matchers.emptyArray()) // invalid expression /
.body(".", Matchers.emptyArray()) // invalid expression .
問題是(可能)REST Assured 返回一個列表而不是一個數組(Hamcrest 區分兩者)。 你可以做:
.body("", Matchers.hasSize(0))
或者
.body("$", Matchers.hasSize(0))
或者
.body("isEmpty()", Matchers.is(true))
受到@Johan 所說的啟發,我嘗試了這個,我認為它比其他建議更能告訴讀者。
.body("", equalTo(Collections.emptyList()))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.