1. 程式人生 > >ssm(6))spring-test

ssm(6))spring-test

return cep spa highlight result public with mode bsp

@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

ssm(6))spring-test