J'utilise MockMVC pour tester une API qui renvoie le contenu JSON et que JSON peut contenir un champ appelé actions strong> comme une matrice vide ou peut-être ne pas exister du tout (je veux dire partage strong> champ). échantillon JSON: p> Comment affirmer que ce champ est vide ou non existé p> < p> J'aime: p>
3 Réponses :
regarder regarder Jsonpath ou condition avec MockMVC
.andExpect(jsonPath("$.isPass", anyOf(is(false),is(true))));
import static org.hamcrest.collection.IsEmptyCollection.empty; .andExpect(jsonPath("$.isPass",empty() ));
Si vous avez quelque chose comme ceci:
.andExpect( jsonPath( "$.arrayFieldName", Matchers.empty() );