MockMvc

Spring's test tool that sends requests through the full Spring MVC machinery to your controllers without opening a real network port.

In more detail

A MockMvc test asserts what an HTTP client would observe: status, headers, content type and JSON fields. Depending on setup it loads one controller or a whole web slice including validation and controller advice. It catches route and serialization drift quickly while leaving the database to integration tests.

Example

mockMvc.perform(get("/orders/one")).andExpect(status().isOk()).andExpect(jsonPath("$.id").value("one"));

Related terms

Taught in

References