Junit5 mock a static method

Priya picture Priya · Oct 16, 2018 · Viewed 20.6k times · Source

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

Answer

Ecsedi Gergő picture Ecsedi Gergő · Oct 24, 2018

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.