问题
I want to mock a static method in junit5. But unfortunately, Junit5 does'nt support Powermockito. Is there any other methods to achieve the same other than reverting back to Junit4
回答1:
Short answer no, as PowerMockito team is done with their work and waiting for JUnit team for extension and discussing here a lot.
With some overhead you can: As JUnit5 provides support running legacy JUnit4, and there you can use PowerMockito. So you can create tests in Junit4 for these cases: Sample project for migration setup with gradle and with mvn. From there I am using PowerMock 2.0 beta with Mockito2.
回答2:
The reason why Mockito doesn't provide static methods mocking at the moment is because of the common belief that static method shouldn't need to be mocked. However there is an open item for mockito here that discusses the issue. While this doesn't answer your question, in general it tells you why you shouldn't need the feature at all or will allow you to join the conversation with your ideas.
来源:https://stackoverflow.com/questions/52830441/junit5-mock-a-static-method