Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Please support @TestSubject (EasyMock's equivalent to Mockito's @InjectMocks) #605
I spent quite a bit of time studying PowerMock's API documentation, only to come to the conclusion that there currently is simply no way to automatically have PowerMock inject mocks that were annotated with @mock into the class under test. PowerMockito supports @InjectMocks, but that doesn't work when using PowerMock's EasyMock API. As a result, even though we can conveniently create mocks using @mock, we still have to manually inject each mock using Whitebox.setInternalState(). I'm frankly surprised that there is apparently no more convenient way to take care of this.
My feature request is as follows: could you please add the @Testsubject annotation to PowerMock's EasyMock API? @Testsubject is an annotation that tells EasyMockRunner to inject @mock annotated EasyMock mocks into the class under test. It would make perfect sense for PowerMock to support this annotation as well. It would also create feature parity with PowerMockito in this respect.
To be clear, I'm asking for a PowerMock implementation of this EasyMock annotation: http://easymock.org/api/org/easymock/TestSubject.html
I'm aware that a similar request was made in issue #455, but the reason why that request was rejected was due to the desire to remain as close as possible to the EasyMock API. Since @Testsubject is already an existing annotation in EasyMock, that should not be an issue here.
Thank you kindly for considering my request.
Also, feel free to point out an existing way to automatically have PowerMock (not PowerMockito) inject mocks, if there is one. I really couldn't find any.
I wasn't aware of TestSubject but this is a good suggestion. If you like then please help out will a pull request. You can have a look at how the PowerMockito extension works for InjectMocks and do something similar for the PowerMock EasyMock extension.