Introduce ResultActions.andExpectAll() for soft assertions in MockMvc

Closes gh-26917
This commit is contained in:
Sam Brannen
2021-08-23 13:05:50 +02:00
parent cd078eaad8
commit dd9b99e13d
5 changed files with 107 additions and 174 deletions

View File

@@ -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.