Junit5 模拟一个静态方法 [英] Junit5 mock a static method

查看:59
本文介绍了Junit5 模拟一个静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 junit5 中模拟一个静态方法.但不幸的是,Junit5 不支持 Powermockito.除了恢复到 Junit4 之外,还有其他方法可以实现吗

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

推荐答案

简短的回答不是,因为 PowerMockito 团队已经完成了他们的 工作,等待 JUnit 团队扩展并在这里讨论了很多.

Short answer no, as PowerMockito team is done with their work and waiting for JUnit team for extension and discussing here a lot.

通过一些开销,您可以:由于 JUnit5 支持运行旧版 JUnit4,因此您可以使用 PowerMockito.因此,您可以在 Junit4 中为这些情况创建测试:使用 gradlemvn.从那里我将 PowerMock 2.0 beta 与 Mockito2 一起使用.

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.

这篇关于Junit5 模拟一个静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆