2 qq 27102079 qq_27102079 于 2016.03.22 15:34 提问

Sprin-test测试Controller,断言报错:No ModelAndView found

问题很奇怪:
使用MockMvc测试SpringMVC的Controller层,调用mockMvc.perform(MockMvcRequestBuilders.post("XXXX")的时候无法调用到Controlelr层的代码,且只要XXX是”/xxx“格式的,返回的状态就一直是200,但结果永远都是null。
1、controller注册了的,我检查了很多遍;
2、controller代码没有被调用到,打了断点测试的;
3、即使是随便输的路径,返回值也是200
输出信息:
Handler:
Type = org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler

Async:
Async started = false
Async result = null

Resolved Exception:
Type = null

ModelAndView:
View name = null
View = null
Model = null

FlashMap:
Attributes = null

MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = default
Redirected URL = null
Cookies = []

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!