EasyMock: the sent object calls the actual method

I have a piece of code in unit test,

ClassToBeMocked mock = createMock(ClassToBeMocked.class); //I've statically imported EasyMock.* mock.callMethod(); //This is a void method expectLastCall(); replay(mock); 

But when I run the test, instead of thinking about the wait, callMethod () is actually called. Am I doing something wrong?

I am new to EasyMock or some mocking structure and am locked due to this issue. Any help would be greatly appreciated.

Thanks AndyS

+8
unit-testing mocking easymock
source share
1 answer

This will happen if you mock the class using the β€œfinal” method. EasyMock does not cancel the final method. If you cannot mock the interface and you cannot change the method to non-final, you can use PowerMock along with EasyMock to get around this limitation. This particular use case is described here .

+8
source share

All Articles