我所有的映射都正常工作:
MvcResult mvcResult = this.mockMvc.perform(get("/company/doSomething"))
.andDo(print())
.andExpect(status().isOk())
.andReturn();
从此返回状态 ok
@RequestMapping(value = "/company/doSomething", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Boolean myMethod() {
return false;
}
如果我在控制器方法中设置断点并运行 test n 调试模式,则测试只是通过(未调用断点)并打印出响应 - 没有返回任何内容,我得到了这个:
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = default
Redirected URL = null
Cookies = []
实际的请求看起来像这样
MockHttpServletRequest:
HTTP Method = GET
Request URI = /company/doSomething
Parameters = {}
Headers = {}
Handler:
Type = org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler