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
- Spring MVC — Spring's framework for web applications and APIs, which routes each HTTP request to a controller method and turns its return value into a response.
- test slice — A Spring Boot test that starts only one layer of the application, such as the web layer with @WebMvcTest, to stay fast.
- JSONPath — A small expression language for picking values out of a JSON document, such as $.id for the id field of the top-level object.
- @SpringBootTest — The Spring Boot test annotation that starts the complete application context, proving that all the wiring works together.
Taught in
- Spring Data Repositories — Modern Java: Virtual Threads & High-Throughput Services
- Testing APIs With MockMvc — Modern Java: Virtual Threads & High-Throughput Services