利用Spring的mock对控制层进行单元测试
作者:网络转载 发布时间:[ 2013/8/22 13:26:57 ] 推荐标签:
大环境概述:
java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Client VM (build 17.0-b16, mixed mode, sharing)
spring的版本:3.1.0.RELEASE
spring-mock的版本:1.2.6
采用Spring 注解mvc
控制层:
@Controller
@RequestMapping("/case")
public class CaseController {
@RequestMapping(value = "/list", method = RequestMethod.POST)
public String list(HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
request.setAttribute("name", name);
List<String> result = new ArrayList<String>();
result.add("result1");
result.add("result2");
result.add("result3");
request.setAttribute("result", result);
return "case/list";
}
@RequestMapping(value = "/listJson", method = RequestMethod.POST)
@ResponseBody
public List<String> listJson(HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
List<String> result = new ArrayList<String>();
result.add("result1");
result.add("result2");
result.add("result3");
return result;
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11