【发布时间】:2016-12-10 20:29:06
【问题描述】:
我需要模拟一个类的静态方法并在我的测试中使用该模拟方法。现在看来我只能使用 PowerMock 来做到这一点。
我使用@RunWith(PowerMockRunner.class) 注释类,并使用适当的类注释@PrepareForTest。
在我的测试中,我有一个@ClassRule,但是在运行测试时,该规则没有正确应用。
我能做什么?
RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.xml.*",
"org.xml.*",
"org.w3c.*",
"javax.management.*"
})
@PrepareForTest(Request.class)
public class RoleTest {
@ClassRule
public static HibernateSessionRule sessionRule = new HibernateSessionRule(); // this Rule doesnt applied
【问题讨论】:
-
仅用于追踪:github.com/powermock/powermock/issues/687。 PowerMock 基本上破坏了 JUnit 测试处理,并且没有真正的计划来修复它。
标签: java junit powermockito