MockMvc is a Spring testing API for calling Spring MVC controllers without starting a real HTTP server. It lets controller integration tests check an endpoint’s contract, including its URL, request, response, and validation behavior. section 16.2
A typical test follows two steps:
- Configure a MockMvc instance using the web application context. section 16.2
- Send a request and check the response. Choose which objects in the request-processing flow are real and which are replaced with mocks. section 16.2
Testing a money transfer
A test can send a JSON POST request to /transfer with sender and receiver IDs and an amount, then assert that the response status is OK. section 16.2
Figure 16.2 A controller integration test. A tool such as MockMvc lets the test execute the web layer without starting a real server. The test sends a simulated HTTP request to the controller, while the developer decides which objects in the request-processing flow are real and which ones are replaced with mocks.

The diagram shows a simulated request reaching the web layer without a real server, with real or mocked objects in the request-processing flow. section 16.2

