Mocking a concrete class using EasyMock

时间秒杀一切 提交于 2019-12-04 03:28:20

问题


Is it possible? How do I do it?


回答1:


See the EasyMock Class Extension documentation and download it from the SourceForge project. You can't mock final methods though.

EDIT: This is now part of EasyMock for v3 and above, as noted in comments.




回答2:


Powermock extends EasyMock and allows you to mock concrete types, even final and static methods.

PowerMock is a framework that extend other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more.




回答3:


Yes: http://easymock.org/EasyMock2_4_ClassExtension_Documentation.html




回答4:


EasyMock class extensions have been integrated into EasyMock as of v3.0; see the release notes.




回答5:


When creating a mock, simply use the org.easymock.classextension version of the EasyMock class. The result will be castable.

Here's a recent link - http://easymock.org/EasyMock3_2_ClassExtension_Documentation.html



来源:https://stackoverflow.com/questions/1249317/mocking-a-concrete-class-using-easymock

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!