PowerMock Classloader而不是System Classloader,违反PowerMockrule抱怨


@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依赖关系/属性按以下顺序:

  1. PowerMock-version 1.6.6
  2. easymock-version 3.4
  3. easymock
  4. PowerMock-Module-Junit4
  5. PowerMock-Api Asymock
  6. PowerMock-Module-Junit4-Rule-lule-agent(删除这会导致构造函数问题(
  7. PowerMock-Module-Junit4-Rule(删除这种依赖性没有效果(
  8. 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

如果您在需要使用其他跑步者的情况下使用其他跑步者。

相关内容

  • 没有找到相关文章

最新更新