标签:wired init form mvc contexts .post res stl mode
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration//注解该注解之后才能获取@Autowired的context @ContextConfiguration({"classpath:application.xml","classpath:springmvc.xml"}) public class SpringTestContorllerTest { @Autowired WebApplicationContext context; MockMvc mockMvc; @Before public void initMockMvc(){ mockMvc= MockMvcBuilders.webAppContextSetup(context).build(); } @Test public void testLogin() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/modelAttribute").param("pwd", "123") .param("pwd", "123456")).andReturn(); MockHttpServletRequest request = mvcResult.getRequest(); MockHttpServletResponse response = mvcResult.getResponse(); } }
待续:spring -test
标签:wired init form mvc contexts .post res stl mode
原文地址:https://www.cnblogs.com/gg128/p/9795340.html