rewrite-spring
rewrite-spring copied to clipboard
MockMvc Soft Assertions recipe
Spring Framework 5.3 added support for soft assertions to MockMvc, as detailed on slides 36 & 37 here.
These allow you to check multiple conditions and report on all of them, rather than just report on the first one that fails.
mockMvc.perform(get("/person/5").accept(APPLICATION_JSON))
- .andExpect(status().isOk())
- .andExpect(jsonPath("$.name").value("Jane"));
+ .andExpectAll(
+ status().isOk(),
+ jsonPath("$.name").value("Jane"));
This helps debugging when a test fails, as you not only get the status code (something like 4xx/5xx), but also the content body.
Would seem doable to pick up as a recipe to aid that migration, so figured pitch it here for anyone willing to work on that (or until I find the time).
Thanks for the detailed suggestion @timtebeek !