@RunWith(PowerMockRunner.class)
@PrepareForTest(StaticMethodsHolder.class)
public class MockNTestStaticMethodsHolder {
@Rule public PowerMockRule rule = new PowerMockRule();
@Test public void staticSvcClientMethod () {
// blah blah blah
mockstatic (StaticMethodsHolder.class);
expect (StaticMethodsHolder.TomBradyIsStillTheBest()).andReturn(UNQUESTIONABLY);
expect (StaticMethodsHolder.NEPatriotsStillTheBest()).andReturn(MAYBE);
expect (StaticMethodsHolder.NEPatriotsLiiWereIdiots()).andReturn(TOTALLY);
expect (StaticMethodsHolder.NEPatriotsWinsLiii()).andReturn(RU_KIDDING_ME);
}
}
maven依赖关系/属性按以下顺序:
- PowerMock-version 1.6.6
- easymock-version 3.4
- easymock
- PowerMock-Module-Junit4
- PowerMock-Api Asymock
- PowerMock-Module-Junit4-Rule-lule-agent(删除这会导致构造函数问题(
- PowerMock-Module-Junit4-Rule(删除这种依赖性没有效果(
- powermock-classloading-xstream
运行时错误:
java.lang.IllegalStateException PowerMockRule can only be used
with the system classloader but was loaded by
org.powermock.core.classloader.MockClassLoader.
PowerMock咬人是自己的尾巴。它想使用自己的classloader,但JVM表示必须由系统加载PowerMockrule。
我该怎么办?
您已经在使用PowerMockRunner,您不需要使用该规则。
https://github.com/powermock/powermock/wiki/powermockrule
如果您在需要使用其他跑步者的情况下使用其他跑步者。