有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用MockMvc使用删除方法rest api从存储库测试deleteAll()

我正在RESTAPI上进行集成测试,除了这个测试之外,所有测试都可以工作

@Test
public void deleteAllUsers_should_return_noContent() throws Exception {
    //Given
    //When
    ResultActions resultActions = mockMvc
            .perform(delete("/pair?delAll"));
    //Then
    resultActions
            .andDo(print())
            .andExpect(status().isNoContent());
}

我期待一个204 http状态,但它得到一个400。以下是该方法的代码:

@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll")
public ResponseEntity<Void> deleteAllUsers() {
    userRepository.deleteAll();
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

你知道我做错了什么吗

编辑:找到的解决方案只是在这些行中添加“=true”

@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll=true")

ResultActions resultActions = mockMvc
            .perform(delete("/pair?delAll=true"));

共 (0) 个答案