MockMvc
MockMvc is a Spring testing API that simulates HTTP requests to Spring MVC components and evaluates their responses without requiring a running web server.
Spring Start Here, Second Edition
MockMvc is a Spring testing API that performs requests against Spring MVC controllers without starting a real HTTP server.
- How it is used
- Tests Spring MVC endpoints as part of controller integration testing.
- How deep it goes
- Demonstrates client configuration, request construction, and response-status checks without detailing MockMvc internals.
- Examples
- Uses a JSON POST to /transfer and checks for an OK response.
- What you can do after
- Apply MockMvc to send endpoint requests and validate responses without starting a real HTTP server.
Read how Spring Start Here, Second Edition explains MockMvc →
Spring Security in Action, Second Edition
MockMvc is a Spring testing utility that performs simulated HTTP requests against MVC application components without requiring a running server.
- How it is used
- Tests endpoint authorization in non-reactive Spring applications through simulated HTTP calls.
- How deep it goes
- Demonstrates setup, requests, response assertions, mock users, and SecurityContext behavior, while deferring reactive testing to WebTestClient.
- Examples
- Uses /hello requests expecting 401 Unauthorized without authentication and 200 OK with a mock user.
- What you can do after
- Apply it via Spring test annotations and MockMvc request builders to verify secured endpoint responses.
Read how Spring Security in Action, Second Edition explains MockMvc →
Also covered in
- Testing Spring Boot ApplicationsIn early access (MEAP)
- Spring in Action, Sixth Edition
- Automating API Delivery
What to know first
- HTTP status codeAn HTTP status code is a standardized three-digit code in an HTTP response that indicates the outcome of processing a request.
Related concepts
- controller integration testused by · A controller integration test verifies a web controller's endpoint contract, including request handling and response behavior.
- HTTP GETuses · HTTP GET is a safe, idempotent HTTP method that requests a representation of a resource without intending to change its state.
- MockMvcTesterpart of · MockMvcTester is an AssertJ-based Spring testing API for exercising Spring MVC request handling without starting an external web server.
- software testingused by · Software testing is the systematic evaluation of software under specified inputs or conditions to assess its behavior against expected results or requirements and identify defects.
- @AutoConfigureMockMvcused by · @AutoConfigureMockMvc is a Spring Boot test annotation that configures MockMvc-based testing support in an application test context.
Questions about MockMvc
What is MockMvc?
MockMvc is a Spring testing API that simulates HTTP requests to Spring MVC components and evaluates their responses without requiring a running web server.
Which Manning books explain MockMvc?
Spring Start Here, Second Edition and Spring Security in Action, Second Edition.
What should I know before learning MockMvc?
Manning books that teach MockMvc usually introduce HTTP status code first.
What is MockMvc part of?
MockMvc is part of MockMvcTester. MockMvcTester is an AssertJ-based Spring testing API for exercising Spring MVC request handling without starting an external web server.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

