问题 断言响应正文是空列表,并且放心


如果响应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 .

7342
2018-05-26 13:57


起源

如果它可以帮助,这通过匹配器: Object array[] = new Object[0];  new MatcherAssert().assertThat(array, Matchers.emptyArray()); - romfret


答案:


问题是(可能)REST Assured返回List而不是数组(和Hamcrest区分两者)。你可以做:

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

要么

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

要么

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

14
2018-05-26 14:09



是的,这似乎是问题所在。 Matchers.empty() 是最清楚的方式imo。 - atamanroman