我在我的JUnit中测试Restful端点并在列表中获得如下所示的异常,该异常作为save方法中的参数出现,
**"Argument(s) are different! Wanted:"**
save(
"121",
[com.domain.PP@6809cf9d,
com.domain.PP@5925d603]
);
Actual invocation has different arguments:
save(
"121",
[com.domain.PP@5b6e23fd,
com.domain.PP@1791fe40]
);
Run Code Online (Sandbox Code Playgroud)
当我调试代码时,代码在下面的验证行中断开并引发了上述异常.看起来save方法中"testpPList"内的参数是不同的.我不知道它是如何变得不同,因为我正确地在我的JUNit中构造它们然后调用RestFul URL.
请求您的宝贵意见.谢谢.
码:
@Test
public void testSelected() throws Exception {
mockMvc.perform(put("/endpointURL")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(testObject)))
.andExpect(status().isOk());
verify(programServiceMock, times(1)).save(id, testpPList);
verifyNoMoreInteractions(programServiceMock);
}
Run Code Online (Sandbox Code Playgroud)
控制器方法:
@RequestMapping(value = "/endpointURL", method = RequestMethod.PUT)
public @ResponseBody void uPP(@PathVariable String id, @RequestBody List<PPView> pPViews) {
// Code to construct the list which is passed into the save method below
save(id, pPList);
}
Run Code Online (Sandbox Code Playgroud)