Thursday, July 9, 2009

EasyMock IllegalStateException: missing behavior definition for last method call

When you encounter this error, please check whether you tried to use the mock object before invoking EasyMock.replay() method. I did that encountered the IllegalStateException and spent quite some time until I figured out the reason.

I had written the following expect() ;

EasyMock.expect(testObj.getTestMethod()).andReturn("testValue");

the culprit was the following statement which I had put before the expect().

System.out.println("testObj="+testObj.getTestMethod());

Hope it helps someone!

3 comments:

  1. That was a big help. Thanks :)

    ReplyDelete
  2. Really helpful. I spent quite some time trying to figure out the solution and I coulnt find it anywhere else. Thanks..!!

    ReplyDelete