openrewrite / rewrite-spring

OpenRewrite recipes for Spring projects.
Apache License 2.0
256 stars 77 forks source link

MockMvc Soft Assertions recipe #196

Open timtebeek opened 2 years ago

timtebeek commented 2 years ago

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).

pway99 commented 2 years ago

Thanks for the detailed suggestion @timtebeek !