接口 ResultActions
public interface ResultActions
Allows applying actions, such as expectations, on the result of an executed
request.
See static factory methods in
MockMvcResultMatchers and
MockMvcResultHandlers.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Sam Brannen, Michał Rowicki
-
方法概要
修饰符和类型方法说明andDo(ResultHandler handler) Perform a general action.andExpect(ResultMatcher matcher) Perform an expectation.default ResultActionsandExpectAll(ResultMatcher... matchers) Perform multiple expectations, with the guarantee that all expectations will be asserted even if one or more expectations fail with an exception.Return the result of the executed request for direct access to the results.static ResultActionsforMvcResult(MvcResult mvcResult)
-
方法详细资料
-
andExpect
Perform an expectation.Example
You can invoke
andExpect()multiple times as in the following example.// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.person.name").value("Jason"));- 抛出:
Exception- 另请参阅:
-
andExpectAll
Perform multiple expectations, with the guarantee that all expectations will be asserted even if one or more expectations fail with an exception.If a single
ErrororExceptionis thrown, it will be rethrown.If multiple exceptions are thrown, this method will throw an
AssertionErrorwhose error message is a summary of all the exceptions. In addition, each exception will be added as a suppressed exception to theAssertionError.This feature is similar to the
SoftAssertionssupport in AssertJ and theassertAll()support in JUnit Jupiter.Example
Instead of invoking
andExpect()multiple times, you can invokeandExpectAll()as in the following example.// static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON), jsonPath("$.person.name").value("Jason") );- 抛出:
Exception- 另请参阅:
-
andDo
Perform a general action.Example
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print());- 抛出:
Exception
-
andReturn
MvcResult andReturn()Return the result of the executed request for direct access to the results.- 返回:
- the result of the request
-
forMvcResult
-