MockMvc tests

MockMvc tests Spring controllers without starting a server: you simulate an HTTP request (perform(get(...))) and verify the status, headers, and JSON body with andExpect. With @WebMvcTest, only the web layer is loaded, and services are replaced by mocks.

Example

mvc.perform(get("/clients/1"))
   .andExpect(status().isOk())
   .andExpect(jsonPath("$.nom").value("Ada"));

Related concepts

The whole glossary