- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为 Controller 层方法编写了一个 jUnit 测试用例,但由于预期结果不匹配而失败。测试用例如下:
@Test
public void testGetNodeStatusCount() throws Exception {
ListNodes listNodes = new ListNodes();
// ArgumentCaptor<Integer> userId = ArgumentCaptor.forClass(Integer.class);
when(userManagementHelper.getNodeStatusCount(0)).thenReturn(
new ResponseEntity<ListNodes>(listNodes, new HttpHeaders(),
HttpStatus.OK));
mockMvc.perform(get("/usermgmt/nodestatus")).andExpect(status().isOk());
}
编写此测试用例的方法如下:
@RequestMapping(value = "/nodestatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<ListNodes> getNodeStatusCount(@RequestParam("userId") int userId) {
return userManagementHepler.getNodeStatusCount(userId);
}
我没有得到的是,如果状态已设置确定,那么我将如何获得 400 而不是 200。
还有一件事我对“ Controller ”的 MockMVC 测试很陌生,所以请建议我一个学习这个的来源。
最佳答案
您的 Controller 需要一个必需的请求参数,这就是您收到状态 400(错误请求)的原因
您可以修改您的测试以包含此请求参数mockMvc.perform(get("/usermgmt/nodestatus?userId=0")).andExpect(status().isOk());
或者您可以将请求参数设置为可选@RequestParam(value = "userId", required = false, defaultValue = "0")
关于java - Controller 的 MockMvc 测试用例中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38829532/
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!