Tag: jsonresponse

unit testingSpring MissingServletRequestParameterException JSON响应

我在Spring引导rest控制器中有POST方法,如下所示 @RequestMapping(value=”/post/action/bookmark”, method=RequestMethod.POST) public @ResponseBody Map bookmarkPost( @RequestParam(value=”actionType”,required=true) String actionType, @RequestParam(value=”postId”,required=true) String postId, @CurrentUser User user) throws Exception{ return service.bookmarkPost(postId, actionType, user); } 现在,如果我在Postman中测试缺少参数,我会获得400个http响应和一个JSON正文: { “timestamp”: “2015-07-20”, “status”: 400, “error”: “Bad Request”, “exception”: “org.springframework.web.bind.MissingServletRequestParameterException”, “message”: “Required String parameter ‘actionType’ is not present”, “path”: “/post/action/bookmark” } 直到现在它没关系,但是当我尝试进行unit testing时,我没有得到JSON响应 @Test public void bookmarkMissingActionTypeParam() throws Exception{ // @formatter:off […]