EasyMock 类扩展模拟不是模拟方法
我的代码中有这样的内容:
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.reset;
import static org.easymock.classextension.EasyMock.verify;
...
mockMember = createMock(Member.class);
mockMember.incrPlayInPlay(200);
因为我想测试 incrPlayInPlay 方法是否被调用。然而,mockMember.incrPlayInPlay 实际上是调用具体类中的方法,而不是设置对模拟的期望。我做错了什么?
I've got this in mycode:
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.reset;
import static org.easymock.classextension.EasyMock.verify;
...
mockMember = createMock(Member.class);
mockMember.incrPlayInPlay(200);
Because I want to tst that the method incrPlayInPlay is called. However, mockMember.incrPlayInPlay is actually calling the method in the concrete class, not setting up the expectations for the mock. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
呃...该方法被定义为最终方法。愚蠢的我。希望这能帮助将来另一个愚蠢的人
Derr... The method was defined as final. Silly me. Hope this helps another silly person in the future
如果需要,您可以使用 PowerMock 模拟最终方法,它会进行一些动态字节码修改以删除最终修饰符。
http://code.google.com/p/powermock/
If you need to, you can mock final methods using PowerMock, which does some on-the-fly bytecode munging to remove the final modifier.
http://code.google.com/p/powermock/