[英]Spring @Controller Unittest @RequestMapping
Having a basic Spring Contoller i'd like to Unittest the Request Mapping (not the Method itself), if the doCriticalStuff
Method is indeed called 有一个基本的Spring控制器我想单元测试请求映射(而不是方法本身),如果确实调用了
doCriticalStuff
方法
package org.foo;
@Controller
public class HelloWorldController implements IHelloWorldController
{
@RequestMapping(value = "/b/c/", method = RequestMethod.GET)
public void doCriticalStuff(HttpServletRequest request, HttpServletResponse response){
//...
}
}
Right now I'm doging this via curl -X GET http://myIP:myPort/b/c/
from commandline in a manual way. 现在我正在通过
curl -X GET http://myIP:myPort/b/c/
以手动方式curl -X GET http://myIP:myPort/b/c/
。 Any Ideas on how to automate it? 关于如何自动化它的任何想法? I could setup a Jetty instance, send a request and see if i get the expected response but isn't there an easier way provided by Spring?
我可以设置一个Jetty实例,发送一个请求,看看我是否得到了预期的响应但是Spring没有提供更简单的方法吗?
Related Post: How to test binders/property editors used on spring 2.5 controllers 相关文章: 如何测试spring 2.5控制器上使用的活页夹/属性编辑器
I'd use a AnnotationMethodHandlerAdapter and call adapter.handle. 我将使用AnnotationMethodHandlerAdapter并调用adapter.handle。 Just send in mock request and response objects along with your controller and spring should take care of the rest.
只需发送模拟请求和响应对象以及控制器,弹簧应该处理其余的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.