Quick revision
The short answer
MockMvc tests the Spring MVC layer in-process without a real server: it is fast and ideal for controllers, but it bypasses the servlet container and real HTTP. MockMvcTester, added in Spring Framework 6.2, wraps MockMvc with AssertJ-style assertions. WebTestClient is the reactive test client; it tests WebFlux apps and can also bind to MockMvc or to a running server. REST Assured sends real HTTP to a running server, testing filters, serialisation and security end to end, readable but slower. Spring Framework 7 adds RestTestClient, a WebTestClient-style client for blocking stacks; check your version for its exact API.
What to remember
In this answer, we compared the main ways to test REST APIs in Spring. MockMvc and MockMvcTester run in-process: fast, on the test thread, ideal for controller tests, but without the servlet container or real HTTP. WebTestClient serves WebFlux and can bind to MockMvc or a running server. RestTestClient in Spring Framework 7 offers the same fluent style for blocking applications. REST Assured sends real HTTP to a running server for end-to-end checks, at the cost of speed and manual cleanup. The practical choice is many fast in-process tests and a smaller set of real HTTP tests.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
MockMvc tests the Spring MVC layer in-process without a real server: it is fast and ideal for controllers, but it bypasses the servlet container and real HTTP. MockMvcTester, added in Spring Framework 6.2, wraps MockMvc with AssertJ-style assertions. WebTestClient is the reactive test client; it tests WebFlux apps and can also bind to MockMvc or to a running server. REST Assured sends real HTTP to a running server, testing filters, serialisation and security end to end, readable but slower. Spring Framework 7 adds RestTestClient, a WebTestClient-style client for blocking stacks; check your version for its exact API.
Why this question is asked
Spring now offers more ways to test a REST API than ever, and teams often end up with three styles in one codebase without a reason for any of them. The choice matters: it decides what each test can catch, how fast the suite runs, and whether tests can roll back their data. Interviewers ask this comparison because it shows whether we understand what each tool actually executes, not just its syntax. In this answer, we will recap the difference between in-process and real HTTP testing, go through each tool with the same small test, compare them side by side, and finish with how I would choose between them in a real project.
1A Quick Recap: In-Process Versus Real HTTP
Every option in the question falls into one of two families. In-process tools call Spring's request handling directly as Java method calls. There is no socket and no servlet container; a mock request object goes into the DispatcherServlet, and a mock response comes out. That is fast, typically a few milliseconds per request, and it runs on the test thread, so a test transaction can roll back what the controller did.
Real HTTP tools send bytes over a socket to a running server, usually the embedded Tomcat that @SpringBootTest(webEnvironment = RANDOM_PORT) starts. Everything a real client would meet is exercised: the servlet container, its filters and error handling, real content negotiation and compression, and the full security filter chain. That is slower, and the request runs on a server thread, so test rollback does not apply. Several of the tools can work in either family depending on how they are bound.
2MockMvc and MockMvcTester
MockMvc is the classic in-process tool for Spring MVC. We build a request, perform it, and chain expectations with static matchers. With @WebMvcTest, only the web layer is loaded, so a controller test starts quickly and mocks its services.
MockMvcTester, introduced in Spring Framework 6.2, runs on the same MockMvc infrastructure but gives AssertJ assertions instead of the andExpect() chain. It reads more like the rest of a modern test, it does not force us to declare throws Exception, and its failures use AssertJ's messages. Spring Boot 3.4 and later can auto-configure it alongside MockMvc when AssertJ is on the classpath. Check your version for the exact assertion method names, as the API is still young. Neither of them tests the servlet container or real HTTP behaviour.
3WebTestClient
WebTestClient was created for Spring WebFlux, the reactive web stack, and its fluent API checks status, headers and body in one chain. It can be bound in several ways: to a WebFlux application in-process, to a running server over real HTTP, and, through MockMvcWebTestClient, to a MockMvc instance, so even a servlet application can use the WebTestClient style.
The catch for servlet applications is the dependency: WebTestClient lives in spring-test but needs spring-webflux on the test classpath, which some teams prefer to avoid in a pure Spring MVC project. That is exactly the gap that RestTestClient fills.
4RestTestClient in Spring Framework 7
Spring Framework 7 adds RestTestClient, a test client with the WebTestClient style built on the blocking RestClient. Like WebTestClient, it can be bound to a single controller, to MockMvc, to the application context, or to a running server, so the same test style works in-process and over real HTTP without bringing WebFlux into a servlet project.
Because it is new, I would check the exact binding methods and the Spring Boot auto-configuration in your versions before standardising on it. The important point for the comparison is its role: it is the blocking counterpart of WebTestClient, and it gives servlet applications one fluent API for both families of tests.
5REST Assured
REST Assured is a third-party library that sends real HTTP to a running server with a given, when, then chain and GPath expressions for JSON. Its tests read almost like an API specification, which makes them popular with QA engineers and for API-focused suites.
Because it goes through the real server, it tests filters, serialisation, error handling and security end to end. The costs are the ones of real HTTP: slower tests, a started server, and data that the test must clean up itself because the server thread commits. REST Assured also has a MockMvc module that runs the same style in-process, which is handy when a team likes the syntax but wants speed.
6Comparing Them and Choosing
Side by side, the tools differ mainly in what they execute and how fast they are.
| Tool | Real HTTP? | Best for | Watch out for |
|---|---|---|---|
MockMvc | No, in-process | Controller tests, many and fast | Skips servlet container and real HTTP |
MockMvcTester (6.2) | No, in-process | Same as MockMvc, AssertJ style | Newer API, check your version |
WebTestClient | Either, by binding | WebFlux apps; fluent style | Needs spring-webflux on the classpath |
RestTestClient (7) | Either, by binding | Blocking apps, one fluent style | New in Framework 7, check your version |
| REST Assured | Yes (or MockMvc module) | End-to-end API checks, readable | Slower; no rollback; manual cleanup |
My default in a Spring MVC service would be this. Controller behaviour, request mapping, validation and error responses are tested in-process with @WebMvcTest and MockMvcTester, because those tests are fast and there will be many of them. A smaller set of full-stack tests goes over real HTTP, with RestTestClient on Spring Framework 7 or REST Assured, to cover what only a real server shows: security filters, servlet error pages, content negotiation and the real JSON configuration. For a WebFlux service, WebTestClient covers both roles. The rule behind it is to use the cheapest tool that executes the code we want to check, and to choose one style per role so that the codebase does not mix four.
7Follow-up questions
Can MockMvc tests miss real bugs?
Yes. Because there is no servlet container, things like a filter registered only in the container, the container's own error page handling, request size limits and some header behaviour are not exercised. Also, if the test is @Transactional, the controller runs inside the test transaction, so lazy loading may work in the test and fail in production. A few real HTTP tests cover those gaps.
Is MockMvcTester a replacement for MockMvc?
It is a different front end for the same engine. Existing MockMvc tests keep working, and new tests can use MockMvcTester for AssertJ assertions. Teams that already use AssertJ everywhere usually find it more consistent.
Why not write every test with REST Assured for maximum realism?
Because realism has a price in speed and isolation. A suite of hundreds of real HTTP tests takes much longer, cannot use rollback, and needs careful data isolation to run in parallel. Most controller behaviour does not depend on the servlet container, so testing it in-process gives the same confidence much more cheaply.
8Conclusion
In this answer, we compared the main ways to test REST APIs in Spring. MockMvc and MockMvcTester run in-process: fast, on the test thread, ideal for controller tests, but without the servlet container or real HTTP. WebTestClient serves WebFlux and can bind to MockMvc or a running server. RestTestClient in Spring Framework 7 offers the same fluent style for blocking applications. REST Assured sends real HTTP to a running server for end-to-end checks, at the cost of speed and manual cleanup. The practical choice is many fast in-process tests and a smaller set of real HTTP tests.
Open with
I split them into in-process and real HTTP. MockMvc calls the DispatcherServlet directly with mock requests, on the test thread, so it's fast and test transactions roll back, which makes it ideal for controller tests with @WebMvcTest.
Then, if they want more
The trade-off is that it skips the servlet container and real HTTP, so container filters, error pages and some header behaviour aren't tested. MockMvcTester, from Spring Framework 6.2, is the same engine with AssertJ assertions and no checked exceptions; Boot 3.4 can auto-configure it. WebTestClient comes from WebFlux.
It's the natural choice for reactive apps, and it can also bind to MockMvc or to a running server, but in a servlet app it pulls in spring-webflux. That's the gap RestTestClient fills in Spring Framework 7: the same fluent style, built on RestClient, bindable to a controller, MockMvc or a live server.
I'd check the exact API in our version. REST Assured sends real HTTP to a running server, so it tests filters, security and serialisation end to end, with very readable given-when-then tests, but it's slower, needs a started server, and data isn't rolled back.
My default for an MVC service is many @WebMvcTest tests with MockMvcTester, plus a small set of full-stack tests over real HTTP with RestTestClient or REST Assured for security, error handling and real JSON configuration.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 7, Spring Framework 6, Spring Boot 3.4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Compare REST Assured, MockMvc, WebTestClient and the newer RestTestClient or...": https://scrivio-interview-library.netlify.app/java/integration-testing/3f14aa569f/