A practical comparison of MockMvcTester and RestTestClient for testing Spring Boot 4 web controllers. Both tools work with mock infrastructure under the hood, with RestTestClient wrapping MockMvc. Key differences: MockMvcTester supports server-side inspection (handler verification, exception details) and multipart file upload testing, while RestTestClient offers a unified API for both mock and real server environments, typed response deserialization, and a familiar WebTestClient-style API. Both support AssertJ-style fluent assertions. The choice largely comes down to personal preference, though RestTestClient is favored for its single infrastructure approach across different test contexts. Code examples demonstrate writing controller tests using both APIs with @WebMvcTest slices and Mockito mocking.
Sort: