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

查看:816
本文介绍了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中针对以下情况创建测试: 使用 gradle 并使用进行迁移设置的示例项目 mvn . 从那里开始,我在Mockito2中使用 PowerMock 2.0 beta .

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天全站免登陆