Documentation for WebTestClient
Issue: SPR-16009
This commit is contained in:
@@ -92,13 +92,26 @@ integration testing framework for Spring MVC. See
|
||||
|
||||
[[mock-objects-web-reactive]]
|
||||
==== Spring Web Reactive
|
||||
The `org.springframework.mock.http.server.reactive` package contains mock request and
|
||||
response objects for testing _Spring WebFlux_ applications. There is also a
|
||||
`MockWebServerExchange` in the `org.springframework.mock.web.server` package that uses
|
||||
those mock request and response objects.
|
||||
The package `org.springframework.mock.http.server.reactive` contains mock
|
||||
implementations of `ServerHttpRequest` and `ServerHttpResponse` for use in WebFlux
|
||||
applications. The package `org.springframework.mock.web.server`
|
||||
contains a mock `ServerWebExchange` that depends on those mock request and response
|
||||
objects.
|
||||
|
||||
`WebTestClient` builds on these mock objects to provide integration testing support for
|
||||
WebFlux server endpoints without running an HTTP server.
|
||||
Both `MockServerHttpRequest` and `MockServerHttpResponse` extend from the same
|
||||
abstract base classes as server-specific implementations do and share behavior with them.
|
||||
For example a mock request is immutable once created but you can use the `mutate()` method
|
||||
from `ServerHttpRequest` to create a modified instance.
|
||||
|
||||
In order for the mock response to properly implement the write contract and return a
|
||||
write completion handle (i.e. `Mono<Void>`), by default it uses a `Flux` with
|
||||
`cache().then()`, which buffers the data and makes it available for assertions in
|
||||
tests. Applications can set a custom write function for example to test an infinite
|
||||
stream.
|
||||
|
||||
The <<webtestclient>> builds on the mock request and response to provide support for
|
||||
testing WebFlux applications without an HTTP server. The client can also be used for
|
||||
end-to-end tests with a running server.
|
||||
|
||||
|
||||
[[unit-testing-support-classes]]
|
||||
@@ -5553,6 +5566,8 @@ https://github.com/spring-projects/spring-framework/tree/master/spring-test/src/
|
||||
tests] of client-side REST tests.
|
||||
|
||||
|
||||
include::testing-webtestclient.adoc[leveloffset=+2]
|
||||
|
||||
|
||||
[[testing-examples-petclinic]]
|
||||
=== PetClinic Example
|
||||
|
||||
Reference in New Issue
Block a user