在同一JUnit测试中同时使用Arquillian和PowerMock

编程入门 行业动态 更新时间:2024-10-09 20:29:59
本文介绍了在同一JUnit测试中同时使用Arquillian和PowerMock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在同一JUnit 4测试中同时使用Arquillian和PowerMock的功能.

I would like to use the features of both Arquillian and PowerMock in the same JUnit 4 test.

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

The problem is that both products are JUnit Runners which should be used with @RunWith, and this is not possible to use multiple @RunWith on the same test class, or to put multiple Runners class in the same @RunWith annotation.

你知道有什么办法吗?

推荐答案

如果使用 PowerMockRule (这是 TestRule ).在PowerMockRule中:

You can use PowerMock without using the runner if you use the PowerMockRule (which is a TestRule). From the PowerMockRule:

从1.4版开始,可以使用JUnit引导PowerMock 规则而不是使用PowerMockRunner和RunWith注释. 这使您可以使用其他JUnit运行器,同时仍能从中受益 PowerMock的功能.您可以通过指定:

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 ... }

另请参阅与Powermock一起进行Junit参数化测试的答案-如何?以及PowerMock谷歌组中的以下线程:使用PowerMock而不使用RunWith?.

See also the answers to Junit Parameterized tests together with Powermock - how? and the following thread in the PowerMock google group: Using PowerMock without the RunWith?.

更多推荐

在同一JUnit测试中同时使用Arquillian和PowerMock

本文发布于:2023-10-31 06:48:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在同一   测试中   PowerMock   JUnit   Arquillian

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!