我正在对REST api进行集成测试,其中所有测试都可以正常运行。
@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状态,但它获得400.以下是该方法的代码:
@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll")
public ResponseEntity<Void> deleteAllUsers() {
userRepository.deleteAll();
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
对于我做错了什么的任何想法?
编辑:找到解决方案只需添加&#34; = true&#34;这些行
@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll=true")
ResultActions resultActions = mockMvc
.perform(delete("/pair?delAll=true"));