springmvc  不经过WEB服务器,如何直接给controller层开始测试。springmvc测试

解决方案 »

  1.   

    ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "xxx.xml" });
    xxxService service = (xxxService) context.getBean("xxxService");
    service.doSomething();
    LZ是说这样的东西吗?
      

  2.   

    不是  还得用到handlermapping和handleradapter 我的程序走到handlermapping不动了,也没报错。
      

  3.   

    spring mvc主要是靠dispatcherServlet来调配..看名字也知道是个servlet,想脱离web容器运行? 可能有..但我觉得没必要
      

  4.   


    还是有必要的,再做持续集成的时候,你需要做单元测试,这个时候通常使用JUNIT来进行测试,在这种情况下,
    直接对Controller来进行测试就比较有必要了。建议LZ去参照下面的文章:
    http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/testing.htmlUnit testing Spring MVC Controllers
    To test your Spring MVC Controllers, use ModelAndViewAssert combined with MockHttpServletRequest, MockHttpSession, and so on from the org.springframework.mock.web package.