【发布时间】:2014-08-09 00:00:10
【问题描述】:
我正在我的 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]
);
当我调试代码时,代码在下面的 verify 行中断并抛出 以上异常。看起来像保存中“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);
}
控制器方法:
@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);
}
【问题讨论】: