0
我是jUnit測試的新手。我有一個請求來測試一個擁有@RequestBody對象的方法。從搜索引擎優化中搜索了近4個小時,但無法找到它。我也讀過類似的問題從堆棧,但沒有解決我的問題。從jUnit春季測試中調用@RequestBody
我的測試控制器:
@Test
public void testInsertRequest() throws Exception {
mockMvc.perform(post("http://localhost:8081/requests/add"))
.andExpect(jsonPath("$.date").value("2017-08-09")).andExpect(jsonPath("$.orderPerson").value("Nermin"))
.andExpect(jsonPath("$.orderPhone").value("0777675432")).andExpect(jsonPath("$.client").value("Nezrin"))
.andExpect(jsonPath("$.clientPhone").value("0776763254")).andExpect(jsonPath("$.department").value("IT"))
.andExpect(jsonPath("$.route").value("Neriman Nerimanov"));
}
和方法,我想測試:
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String insertRequest(@RequestBody EmployeeRequest employeeRequest) {
System.out.println(employeeRequest.getDate());
requestService.insertRequest(employeeRequest);
}
我得到這個錯誤:Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing
。所以我怎麼能叫從junit
@RequestBody