Overview

You can write plain unit tests for Web MVC by instantiating a controller, injecting it with dependencies, and calling its methods. However such tests do not verify request mappings, data binding, message conversion, type conversion, validation, and nor do they involve any of the supporting @InitBinder, @ModelAttribute, or @ExceptionHandler methods.

The Web MVC Test framework, also known as MockMvc, aims to provide more complete testing for Web MVC controllers without a running server. It does that by invoking the MockDispatcher and passing “mock” implementations of the Servlet API from the today-test module which replicates the full Web MVC request handling without a running server.

MockMvc is a server side test framework that lets you verify most of the functionality of a Web MVC application using lightweight and targeted tests. You can use it on its own to perform requests and to verify responses, or you can also use it through the WebTestClient API with MockMvc plugged in as the server to handle requests with.