Mocking a concrete class using EasyMock

后端 未结 5 1648
别跟我提以往
别跟我提以往 2021-01-18 06:15

Is it possible to mock a concrete class using EaskMock? If so, how do I do it?

相关标签:
5条回答
  • 2021-01-18 06:40

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

    0 讨论(0)
  • 2021-01-18 06:43

    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.

    0 讨论(0)
  • 2021-01-18 06:50

    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

    0 讨论(0)
  • 2021-01-18 06:54

    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.

    0 讨论(0)
  • 2021-01-18 06:54

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

    0 讨论(0)
提交回复
热议问题