Consider this code snippet:-
Whatever mock = EasyMock.createMock( Whatever.class );
mock.doSomething();
EasyMock.expectLastCall(); // <- Does this do anything?
EasyMock.replay( whatever );
Does expectLastCall()
here actually do anything? Adding or removing this line from my test appears to make no difference.
Obviously it is useful if you add .andThrow
or .atLeastOnce()
, etc. to the call. That is not what I'm asking about.
No, you only usually use expectLastCall()
when you need the result to specify behaviour. That's its purpose.
Of course, it does no harm to call it if you find it makes your test more readable. For example, I might do that for consistency - if I've had to call it twice in order to specify more behaviour, I might include it a third time even if I didn't need to. I'd probably add the default behaviour explicitly though, just for additional consistency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With