Abh*_*hek 4 java spring unit-testing spring-mvc
我有以下控制器接受输入为 @RequestParam
@RequestMapping(value = "/fetchstatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Response fetchStatus(
@RequestParam(value = "userId", required = true) Integer userId) {
Response response = new Response();
try {
response.setResponse(service.fetchStatus(userId));
response = (Response) Util.getResponse(
response, ResponseCode.SUCCESS, FETCH_STATUS_SUCCESS,
Message.SUCCESS);
} catch (NullValueException e) {
e.printStackTrace();
response = (Response) Util.getResponse(
response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
} catch (Exception e) {
e.printStackTrace();
response = (Response) Util.getResponse(
response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
我需要一个单元测试类,我是spring mvc的初学者.我不知道编写测试类@RequestParam作为输入.
任何帮助将不胜感激 ..
我刚刚解决了这个问题.我刚刚更改了网址.现在它在测试类中包含如下参数:
mockMvc.perform(get("/fetchstatus?userId=1").andExpect(status().isOk());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5602 次 |
| 最近记录: |