Performance: MockMvc for HTTP assertions
This affects backend test execution speed and resource usage during HTTP request simulations.
Use MockMvc to perform HTTP requests directly against the controller layer without starting the server.
Start the full Spring Boot server and use RestTemplate or WebClient to send HTTP requests for tests.
| Pattern | Server Startup | Network Overhead | Test Execution Time | Verdict |
|---|---|---|---|---|
| Full server start + HTTP client | Yes (seconds) | Yes (milliseconds) | Slow (seconds per test) | [X] Bad |
| MockMvc in-memory requests | No | No | Fast (milliseconds per test) | [OK] Good |
MockMvc in Spring Boot tests?mockMvc.perform(get("/url")) with static import of get.mockMvc.perform(get("/hello"))
.andExpect(status().isOk());status().isOk() checks for HTTP status code 200.mockMvc.perform(post("/submit"))
.andExpect(status().isOk)
.andExpect(content().string("Success"));isOk must be called with parentheses: isOk()./user/1 endpoint that returns {"name":"Alice","age":30}. Which MockMvc assertion correctly checks the name field in the JSON response?jsonPath("$.fieldName") with value() for expected value.Pass the test and this pattern moves unknown