我正在使用EasyMock测试我的Java代码。
我想模拟的代码片段如下所示:
requestInfo = mupClient.newEnqueueRequestCall().call(requestArgs);我嘲笑这一点的方式是:
expect(mupClient.newEnqueueRequestCall()).andReturn(enqueueRequestCall);
final Capture<EnqueueRequestArgs> captureRequestArgs =
new Capture<EnqueueRequestArgs>();
expect(mupClient.newEnqueueRequestCall().call(capture(captureRequestArgs))).
andThrow(new MUPCoralException("an exception"));但是requestInfo总是null。即使我将.andThrow()部件更改为.andReturn(new RequestInfo()),它仍然是null。
我查看了另一个类似的帖子,但那不起作用。现在我可以对它发表评论了,因此产生了一个新的问题。
答案:在replay中添加所有模拟的对象!示例replay(mockObj1, mockObj2, ...)
发布于 2012-06-07 07:08:03
试试这个:
expect(mupClient.newEnqueueRequestCall()).andReturn(enqueueRequestCall);
final Capture<EnqueueRequestArgs> captureRequestArgs =
new Capture<EnqueueRequestArgs>();
expect(enqueueRequestCall.call(capture(captureRequestArgs))).
andThrow(new MUPCoralException("an exception"));问题是你的enqueRequestCall应该返回requestInfo。只有当你从easymock调用replay方法后,mupClient才会返回enqueueRequestCall。
https://stackoverflow.com/questions/10923337
复制相似问题