EasyMock 期望与 void 方法
2022-09-01 23:18:13
我正在使用EasyMock进行一些单元测试,我不明白.正如你在下面的代码中看到的,我有一个对象,它的方法返回void,并在其他对象的方法中调用。我认为我必须让EasyMock期望该方法调用,但我尝试注释掉调用,它仍然有效。是因为我通过了,它将其注册为预期呼叫还是发生了其他事情?EasyMock.expectLastCall()
expectLastCall()
EasyMock.anyObject())
MyObject obj = EasyMock.createMock(MyObject.class);
MySomething something = EasyMock.createMock(MySomething.class);
EasyMock.expect(obj.methodThatReturnsSomething()).andReturn(something);
obj.methodThatReturnsVoid(EasyMock.<String>anyObject());
// whether I comment this out or not, it works
EasyMock.expectLastCall();
EasyMock.replay(obj);
// This method calls the obj.methodThatReturnsVoid()
someOtherObject.method(obj);
EasyMock 的 API 文档是这样说的:expectLastCall()
Returns the expectation setter for the last expected invocation in the current thread. This method is used for expected invocations on void methods.