Junit5 mock a static method

南笙酒味 提交于 2020-06-13 18:13:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!