How to ignore unexpected method calls in JUnit/easymock?

11,605

With EasyMock you can create a nice mock, which unlike a normal mock object does not throw assertion errors if an unexpected/recorded call occurs. To quote the easymock documentation...

On a Mock Object returned by createMock() the default behavior for all methods is to throw an AssertionError for all unexpected method calls. If you would like a "nice" Mock Object that by default allows all method calls and returns appropriate empty values (0, null or false), use createNiceMock() instead.

To create a nice mock, use the static createNiceMock(Class class) method on the Easymock class...

SomeClass someClassNiceMock = EasyMock.createNiceMock(SomeClass.class);

Reference: http://easymock.org/user-guide.html#mocking-nice

Share:
11,605
chetan godiya
Author by

chetan godiya

please delete me

Updated on June 05, 2022

Comments

  • chetan godiya
    chetan godiya about 2 years

    I'm just wondering if it is possible using Junit and easymock to ignore unexpected method calls?

    I.e. instead of the test failing I want to be able to say - "at this point - ignore any unexpected method calls and just continue with the test as normal'

    Thanks