2015-05-26 15 views
8

Come posso verificare con rest-assured (2.4.0) se la risposta json è una lista vuota?Asserire che il corpo della risposta è una lista vuota con il resto sicuro

Data la risposta [] (con intestazione content-type=application/json) Ho provato:

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

Se potrebbe aiutare, questo passa il matcher: 'matrice Object [] = new Object [0]; ' ' new MatcherAssert(). AssertThat (array, Matchers.emptyArray()); ' – romfret

risposta

12

Il problema è (probabilmente) che poggiano rendimenti assicurati un elenco e non un array (e Hamcrest distinguere tra i due). Si può fare:

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

o

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

o

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

Sì, sembra essere il problema. 'Matchers.empty()' è il modo più chiaro imo. – atamanroman

Problemi correlati