在Junit测试用例中为@RequestBody传递空值

时间:2018-06-11 10:22:48

标签: unit-testing junit junit4 testcase

  

Controller.java

@RequestMapping(value = "/listUsers", method = RequestMethod.POST)
public @ResponseBody String listUsers(
        @Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SearchFormDto dto) throws IOException {
    List<UserInformationDto> users = null; 
    // some statements
}
  

ControllerTest.java

@Test
    public void testListUsers() throws Exception {

        this.mockMvc.perform(post("/superadmin/listUsers").contentType(MediaType.APPLICATION_JSON).content(createSearchFormDto("1","25")))
                .andExpect(status().isOk());
    }

这里我将@RequestBody(SearchFormDto)作为JSON发送。而且我也能够获得价值。它工作正常。

我想将@RequestBody(SearchFormDto)设为null。建议我一些想法。

提前致谢。

0 个答案:

没有答案