类 MockMvc
- java.lang.Object
- org.springframework.test.web.servlet.MockMvc
public final class MockMvc extends Object
Main entry point for server-side Spring MVC test support.Example
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; // ... WebApplicationContext wac = ...; MockMvc mockMvc = webAppContextSetup(wac).build(); mockMvc.perform(get("/form")) .andExpect(status().isOk()) .andExpect(content().mimeType("text/html")) .andExpect(forwardedUrl("/WEB-INF/layouts/main.jsp"));
- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Rob Winch, Sam Brannen
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ResultActions
perform(RequestBuilder requestBuilder)
Perform a request and return a type that allows chaining further actions, such as asserting expectations, on the result.
方法详细资料
perform
public ResultActions perform(RequestBuilder requestBuilder) throws Exception
Perform a request and return a type that allows chaining further actions, such as asserting expectations, on the result.- 参数:
requestBuilder
- used to prepare the request to execute; see static factory methods inMockMvcRequestBuilders
- 返回:
- an instance of
ResultActions
(nevernull
) - 抛出:
Exception
- 另请参阅:
MockMvcRequestBuilders
,MockMvcResultMatchers