接口 ResultActions
public interface ResultActions
Allows applying actions, such as expectations, on the result of an executed request.See static factory methods in
MockMvcResultMatchersandMockMvcResultHandlers.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 ResultActionsandDo(ResultHandler handler)Perform a general action.ResultActionsandExpect(ResultMatcher matcher)Perform an expectation.MvcResultandReturn()Return the result of the executed request for direct access to the results.
方法详细资料
andExpect
ResultActions andExpect(ResultMatcher matcher) throws Exception
Perform an expectation.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"));Or alternatively provide all matchers as a vararg:
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*, ResultMatcher.matchAll mockMvc.perform(post("/form")) .andExpect(matchAll( status().isOk(), redirectedUrl("/person/1"), model().size(1), model().attributeExists("person"), flash().attributeCount(1), flash().attribute("message", "success!")) );- 抛出:
Exception
andDo
ResultActions andDo(ResultHandler handler) throws Exception
Perform a general action.Example
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print());- 抛出:
Exception