Struts2+Spring+Junit单元测试

来源:互联网 发布:淘宝韩版短袖 编辑:程序博客网 时间:2024/05/29 10:10

使用Junit对Struts+spring系统进行单元测试,好处是不用启动tomcat等容器。

简单实例代码如下:

import org.apache.struts2.StrutsSpringTestCase;public class ActionTest extends StrutsSpringTestCase{@Overrideprotected String getContextLocations() {return "classpath*:applicationContext*.xml";}public void testAll() throws Exception{request.addParameter("id", "1");String res=executeAction("/test.action");System.out.println(res);}}


主要是继承StrutsSpringTestCase类。

测试用例中,action返回的数据为json,res即为response的内容。

0 0