spring-framework/framework-docs/modules/ROOT/pages/testing/mockmvc/overview.adoc

25 lines
1.2 KiB
Plaintext
Raw Normal View History

[[mockmvc-overview]]
2023-04-19 23:26:16 +08:00
= Overview
:page-section-summary-toc: 1
2023-04-19 23:26:16 +08:00
You can write plain unit tests for Spring 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.
`MockMvc` aims to provide more complete testing for Spring MVC controllers without a
running server. It does that by invoking the `DispatcherServlet` and passing
2023-04-19 23:26:17 +08:00
xref:testing/unit.adoc#mock-objects-servlet["`mock`" implementations of the Servlet API] from the
2023-04-19 23:26:16 +08:00
`spring-test` module which replicates the full Spring MVC request handling without
a running server.
MockMvc is a server side test framework that lets you verify most of the functionality
of a Spring MVC application using lightweight and targeted tests. You can use it on
its own to perform requests and to verify responses using Hamcrest, or through
`MockMvcTester` that provides a fluent API using AssertJ. Finally, you can also use it
through the xref:testing/webtestclient.adoc[WebTestClient] API with MockMvc plugged in
as the server to handle requests with.
2023-04-19 23:26:16 +08:00