Is it possible to mock a concrete class using EaskMock? If so, how do I do it?
5 Answers. Show activity on this post. In theory there is absolutely no problem mocking a concrete class; we are testing against a logical interface (rather than a keyword interface ), and it does not matter whether that logical interface is provided by a class or interface . In practice .
If we just want to mock void method and don't want to perform any logic, we can simply use expectLastCall(). andVoid() right after calling void method on mocked object. You can checkout complete project and more EasyMock examples from our GitHub Repository.
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.
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.
Yes: http://easymock.org/EasyMock2_4_ClassExtension_Documentation.html
EasyMock class extensions have been integrated into EasyMock as of v3.0; see the release notes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With