• 2007-08-14

    spring mvc单元测试 - [工作学习]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://jimsu.yourblog.org/logs/618480.html

    web单元测试:通过spring Mock对象(spring-mock.jar),能测试spring mvc。 对于不是spring mvc的如何测试,比如普通get请求,或者struts mvc如何去测试了?我想应该也有对应的方法吧,得好好查查。 public class TestTsmScan extends TestCase{ private String[] paths={"springmvc.xml","server-beans.xml"}; private MockServletContext webCtx=null; private XmlWebApplicationContext ctx=null; protected void setUp() throws Exception { ctx=new XmlWebApplicationContext(); ctx.setConfigLocations(paths); webCtx=new MockServletContext(); ctx.setServletContext(webCtx); ctx.refresh(); } public void testViewScanParameter(){ try{ MockHttpServletRequest request=new MockHttpServletRequest("GET","/jsp/topo/topo.do"); request.addParameter("method", "viewScanParameter"); MockHttpServletResponse response=new MockHttpServletResponse(); TopoController controller=(TopoController)ctx.getBean("topoController"); ModelAndView mv=controller.handleRequest(request, response); System.out.println(mv.getModel()); }catch(Exception e){ e.printStackTrace(); } } } 不过,这并没有真正发送http get请求,这点比较不爽.

    收藏到:Del.icio.us




发表评论

您将收到博主的回复邮件
记住我