我正在测试一个控制器,遇到了一个无法解决的问题。我不明白为什么它需要身份证,以及哪里缺少身份证。
这是我的控制器
@GetMapping(value = "/ads/in/rubrics")
public List<Ad> findAllAdInRubricByIds(@RequestParam(value = "ids", required = true) List<Integer> ids) {
return adService.findAllAdInRubricByIds(ids);
}
测试方法
@Test
public void findAllAdInRubricByIds() throws Exception {
List<Ad> ads = new ArrayList<>();
ads.add(initAd());
Mockito.when(controller.findAllAdInRubricByIds(((ArgumentMatchers.anyList())))).thenReturn(ads);
mockMvc.perform(
get("/ad/ads/in/rubrics"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].id").value(0));
}
错误
MockHttpServletResponse:
Status = 400
Error message = Required List parameter 'ids' is not present
Headers = []
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
java.lang.AssertionError: Status
Expected :200
Actual :400
如错误中所述-所需列表参数"ids"不存在,请在请求参数中添加id,如下所示:
mockMvc.perform(
get("/ad/ads/in/rubrics?ids=1,2,3"))