简体   繁体   中英

Use JMockit to test the concrete methods of an abstract class

I have an abstract base class that defines both concrete and abstract methods. I'm wondering if there's a way, using JMockit, to mock this type such that I can declare expectations for the abstract methods and test the implementation of the concrete methods.

Clearly I can do this without using any mocking framework simply be defining a subclass of the abstract one in my test. Then I can override the abstract methods to return whatever I need. I'm just wondering if there's a slicker, black-magic JMockit way to do this.

Use @Mocked on the abstract class and record/verify expectations on its abstract methods. If you want to execute the non-abstract methods in the mocked class, then apply partial mocking by passing the mocked instance created by JMockit to the Expectations(Object...) or NonStrictExpectations(Object...) constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM