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.
本文介绍如何使用EasyMock框架正确模拟返回值的方法。当一个类的方法需要被模拟并返回特定值时,应在单元测试中明确指定返回值。文章通过示例说明了如何避免因未设置返回值而引发的IllegalStateException异常。
192

被折叠的 条评论
为什么被折叠?



