Introduce ResultActions.andExpectAll() for soft assertions in MockMvc
Closes gh-26917
This commit is contained in:
@@ -7219,8 +7219,9 @@ they must be specified on every request.
|
||||
[[spring-mvc-test-server-defining-expectations]]
|
||||
===== Defining Expectations
|
||||
|
||||
You can define expectations by appending one or more `.andExpect(..)` calls after
|
||||
performing a request, as the following example shows:
|
||||
You can define expectations by appending one or more `andExpect(..)` calls after
|
||||
performing a request, as the following example shows. As soon as one expectation fails,
|
||||
no other expectations will be asserted.
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
@@ -7240,6 +7241,21 @@ performing a request, as the following example shows:
|
||||
}
|
||||
----
|
||||
|
||||
You can define multiple expectations by appending `andExpectAll(..)` after performing a
|
||||
request, as the following example shows. In contrast to `andExpect(..)`,
|
||||
`andExpectAll(..)` guarantees that all supplied expectations will be asserted and that
|
||||
all failures will be tracked and reported.
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
// static import of MockMvcRequestBuilders.* and MockMvcResultMatchers.*
|
||||
|
||||
mockMvc.perform(get("/accounts/1")).andExpectAll(
|
||||
status().isOk(),
|
||||
content().contentType("application/json;charset=UTF-8"));
|
||||
----
|
||||
|
||||
`MockMvcResultMatchers.*` provides a number of expectations, some of which are further
|
||||
nested with more detailed expectations.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user