I've been experimenting the Mockito equivalent of the
EasyMock.expect(someMethod()).andReturn(someMockObject).times(n);
but I can't figure it out.
A little help on this, please?
Thanks in advance.
The andReturn() method defines the return value of this method for the specified method parameters. The times() method defines how often the Mock object will be called. The replay() method is called to make the Mock object available. // setup the mock object expect(calcMethod.
Mockito Behavior Verification To add a behavior to the mocked class when() and thenReturn() functions are used. It means that when the mock object (addService) is called for add method with (num1, num2) parameters, then it returns the value stored in the expected variable.
JMockit will be the chosen option for its fixed-always-the-same structure. Mockito is more or less THE most known so that the community will be bigger. Having to call replay every time you want to use a mock is a clear no-go, so we'll put a minus one for EasyMock. Consistency/simplicity is also important for me.
when(myObject.someMethod()).thenReturn(someMockObject);
// run test
verify(myObject, times(n)).someMethod();
See the documentation for more conversion examples.
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