加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

单元测试 – 在同一个JUnit测试中使用Arquillian和PowerMock

发布时间:2020-12-14 06:06:25 所属栏目:Java 来源:网络整理
导读:我想在同一个JUnit 4测试中使用Arquillian和PowerMock的功能. 问题是两个产品都是JUnit Runners,它应该与@RunWith一起使用,这不可能在同一个测试类上使用多个@RunWith,或者将多个Runners类放在同一个@RunWith注释中. 你知道有什么办法吗 解决方法 如果您使用
我想在同一个JUnit 4测试中使用Arquillian和PowerMock的功能.

问题是两个产品都是JUnit Runners,它应该与@RunWith一起使用,这不可能在同一个测试类上使用多个@RunWith,或者将多个Runners类放在同一个@RunWith注释中.

你知道有什么办法吗

解决方法

如果您使用 PowerMockRule(这是 TestRule),则可以使用PowerMock而不使用转轮.从PowerMockRule:

Since version 1.4 it’s possible to bootstrap PowerMock using a JUnit
Rule instead of using the PowerMockRunner and the RunWith annotation.
This allows you to use other JUnit runners while still benefiting from
PowerMock’s functionality. You do this by specifying:

@RunWith(Arquillian.class);
public class MyTest {
    @Rule
    PowerMockRule rule = new PowerMockRule();

    // Tests goes here
    ...
}

另请参阅Junit Parameterized tests together with Powermock – how?的答案和PowerMock谷歌组中的以下线程:Using PowerMock without the RunWith?.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读