只是第一次尝试EasyMock。
我似乎让它运行起来了,但我立即停止了,因为被模仿的类运行了一个“返回”空的方法(EntityManager.remove(abc))。
我能够部分地模拟EntityManger以开始测试,即
EasyMock.expect(this.mockManager.find(Some.class, id)).andReturn(mock);,但是我如何对'remove‘情况做同样的事情呢?
我不能做(举个例子):
EasyMock.expect(this.mockManager.remove(rek)).andReturn(Boolean(true));如果我什么都不做,我会得到:
java.lang.AssertionError:
Unexpected method call EntityManager.remove(EasyMock for class my.package.Some)...在删除part之前,我需要测试逻辑,但我并不关心它是否真的成功(这将是另一回事)。
发布于 2013-04-30 19:46:20
您不需要调用EasyMock.expect()。只需使用
this.mockManager.remove(rek);处于录制阶段(在调用replay()之前)。
例如,如果希望mocked方法抛出异常或调用两次,请使用expectLastCal()
this.mockManager.remove(rek);
expectLastCall().andThrow(new RuntimeException());
//or expectLastCall().times(2);https://stackoverflow.com/questions/16298696
复制相似问题