问题描述
- 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.DefaultServletHttpRequestHandlerAsync:
Async started = false
Async result = nullResolved Exception:
Type = nullModelAndView:
View name = null
View = null
Model = nullFlashMap:
Attributes = nullMockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = default
Redirected URL = null
Cookies = []
时间: 2024-09-16 18:36:21