首页 > 编程语言 > 详细

ssm(6))spring-test

时间:2018-10-16 00:10:42      阅读:179      评论:0      收藏:0      [点我收藏+]
@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

原文:https://www.cnblogs.com/gg128/p/9795340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!