EasyMock: missing behavior definition for the preceeding method call

来源:互联网 发布:java入门编程实例 编辑:程序博客网 时间:2024/04/30 23:30

If a method of a class which will be mocked by EasyMock did return some value, you should specify the return value explicitly before you use the mock object in your unit test case. Or else EasyMock will complain:

 

java.lang.IllegalStateException: missing behavior definition for the preceeding method call xxx

 

An example:

Say we have a interface named Subject which has a member method as follows:

 

 

 

Then we should use EasyMock to mock this interface in following way:

 

 

 

Note the line contains andReturn. If you missed the call to andReturn, EasyMock will throw out the above IllegalStateException.

 

 

原创粉丝点击