Junit参数化测试与Powermock一起 - 如何? [英] Junit Parameterized tests together with Powermock - how?

查看:330
本文介绍了Junit参数化测试与Powermock一起 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图弄清楚如何在Junit4中与PowerMock一起运行参数化测试。问题是要使用PowerMock,你需要装饰你的测试类

  @RunWith(PowerMockRunner.class)

并使用参数化测试你需要用



$ b <$ p来装饰$ p> @RunWith(Parameterized.class)

从我看到的他们似乎相互排斥!?这是真的?有没有办法解决?我试图在运行PowerMock的类中创建一个参数化类;类似这样的事情:

  @RunWith(PowerMockRunner.class)
class MyTestClass {
@RunWith(参数化) .class)
class ParamTestClass {
// Yadayada
}
}

但不幸的是,这并没有太大的好处...... ParamTestClass 仍然无法运行PowerMock支持(也许并不令人惊讶)...我有点想法,所以任何帮助都非常感谢!



更新:
对于未来的googlers也看到了:在没有RunWith的情况下使用PowerMock?

解决方案

我遇到了同样的问题。不幸的是,由于我拥有的JVM,它不会让我使用PowerMock规则。而不是我使用RunnerDelegate的规则。

  @RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(Parameterized.class)


I've been trying to figure out how to run parameterized tests in Junit4 together with PowerMock. The problem is that to use PowerMock you need to decorate your test class with

@RunWith(PowerMockRunner.class)

and to use parameterized tests you have to decorate with

@RunWith(Parameterized.class)

From what I can see they seem mutually excluded!? Is this true? Is there any way around this? I've tried to create a parameterized class within a class running with PowerMock; something like this:

@RunWith(PowerMockRunner.class)
class MyTestClass {
     @RunWith(Parameterized.class)
     class ParamTestClass {
          // Yadayada
     }
}

But unfortunately this doesn't do much good... The ParamTestClass still doesn't run with PowerMock support (not that surprisingly maybe)... And I've kind of run out of ideas so any help is greatly appreciated!

Update: For future googlers also see: Using PowerMock without the RunWith?

解决方案

I had the same issue. Unfortunately it would not let me use a PowerMock Rule due to the JVM I had. Instead of the rule I used RunnerDelegate.

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(Parameterized.class)

这篇关于Junit参数化测试与Powermock一起 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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