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

标签 unit-testing junit powermock jboss-arquillian

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

问题在于这两个产品都是JUnit Runner,应与@RunWith一起使用,并且不可能在同一个测试类上使用多个@RunWith,或者在同一个Runner批注中放置多个@RunWith s类。

你知道有什么办法吗?

最佳答案

如果使用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?

关于unit-testing - 在同一JUnit测试中同时使用Arquillian和PowerMock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9496552/

相关文章:

Powermock 与 Guidewire 集成

java - jacoco 仅显示同一模块中类的覆盖率

unit-testing - 单元测试 - 它真正增加了多少时间?

java - 无法接收嵌入的 ActiveMQ 统计消息

java - 使用 Mockito 检查单元测试中传递的参数

java - 我正在为 Java Stream 中的泛型而苦苦挣扎

java - JUnit assertEquals for double with percentage delta

iphone - 如何等待单元测试动画完成

c# - 类型 'TestClassAttribute' 存在于 'Microsoft.VisualStudio.QualityTools.UnitTestFramework and ' Microsoft.VisualStudio.TestPlatform.TestFramework

java - Powermock 不断为 ScriptEngineManager 抛出错误