@ -140,7 +214,7 @@ The following server setup option lets you connect to a running server:
@@ -140,7 +214,7 @@ The following server setup option lets you connect to a running server:
[[webtestclient-client-config]]
=== Client Builder
=== Client Config
In addition to the server setup options described earlier, you can also configure client
options, including base URL, default headers, client filters, and others. These options
@ -6488,151 +6488,83 @@ of `AbstractTestNGSpringContextTests` for an example of how to instrument your t
@@ -6488,151 +6488,83 @@ of `AbstractTestNGSpringContextTests` for an example of how to instrument your t
[[spring-mvc-test-framework]]
=== Spring MVC Test Framework
The Spring MVC Test framework provides first class support for testing Spring MVC code
with a fluent API that you can use with JUnit, TestNG, or any other testing framework. It
is built on the {api-spring-framework}/mock/web/package-summary.html[Servlet API mock objects]
from the `spring-test` module and, hence, does not use a running Servlet container. It
uses the `DispatcherServlet` to provide full Spring MVC runtime behavior and provides
support for loading actual Spring configuration with the TestContext framework in
addition to a standalone mode, in which you can manually instantiate controllers and test
them one at a time.
Spring MVC Test also provides client-side support for testing code that uses the
`RestTemplate`. Client-side tests mock the server responses and also do not use a running
server.
TIP: Spring Boot provides an option to write full, end-to-end integration tests that
include a running server. If this is your goal, see the
@ -6643,14 +6575,13 @@ configuration and injects a `WebApplicationContext` into the test to use to buil
@@ -6643,14 +6575,13 @@ configuration and injects a `WebApplicationContext` into the test to use to buil
@ -6658,21 +6589,23 @@ configuration and injects a `WebApplicationContext` into the test to use to buil
@@ -6658,21 +6589,23 @@ configuration and injects a `WebApplicationContext` into the test to use to buil
}
----
Your second option is to manually create a controller instance without loading Spring
configuration. Instead, basic default configuration, roughly comparable to that of the
MVC JavaConfig or the MVC namespace, is automatically created. You can customize it to a
degree. The following example shows how to do so:
Or you can also use this setup when testing through the
<<webtestclient-controller-config, WebTestClient>> which delegates to the same builder
as shown above.
To set up MockMvc through Spring configuration, use the following:
@ -6697,6 +6631,12 @@ degree. The following example shows how to do so:
@@ -6697,6 +6631,12 @@ degree. The following example shows how to do so:
}
----
Or you can also use this setup when testing through the
<<webtestclient-context-config, WebTestClient>> which delegates to the same builder
as shown above.
Which setup option should you use?
The `webAppContextSetup` loads your actual Spring MVC configuration, resulting in a more
@ -6826,7 +6766,11 @@ for a list of all MockMvc builder features or use the IDE to explore the availab
@@ -6826,7 +6766,11 @@ for a list of all MockMvc builder features or use the IDE to explore the availab
[[spring-mvc-test-server-performing-requests]]
===== Performing Requests
You can perform requests that use any HTTP method, as the following example shows:
This section shows how to use MockMvc on its own to perform requests and verify responses.
If using MockMvc through the `WebTestClient` please see the corresponding section on
<<webtestclient-tests>> instead.
To perform requests that use any HTTP method, as the following example shows:
WebTestClient]. Browse these examples for further ideas.
[[spring-mvc-test-server-htmlunit]]
@ -8359,7 +8305,7 @@ http://www.gebish.org/manual/current/[The Book of Geb] user's manual.
@@ -8359,7 +8305,7 @@ http://www.gebish.org/manual/current/[The Book of Geb] user's manual.
[[spring-mvc-test-client]]
==== Client-Side REST Tests
=== Testing Client Applications
You can use client-side tests to test code that internally uses the `RestTemplate`. The
idea is to declare expected requests and to provide "`stub`" responses so that you can
@ -8478,7 +8424,7 @@ logic but without running a server. The following example shows how to do so:
@@ -8478,7 +8424,7 @@ logic but without running a server. The following example shows how to do so:
----
[[spring-mvc-test-client-static-imports]]
===== Static Imports
==== Static Imports
As with server-side tests, the fluent API for client-side tests requires a few static
imports. Those are easy to find by searching for `MockRest*`. Eclipse users should add
@ -8489,14 +8435,12 @@ the static method name. Other IDEs (such IntelliJ) may not require any additiona
@@ -8489,14 +8435,12 @@ the static method name. Other IDEs (such IntelliJ) may not require any additiona
configuration. Check for the support for code completion on static members.