我想使用powerMockito + testng进行测试,测试代码为: 而我的powerMockito版本是1.6.3,testng版本是6.8.7
@PrepareForTest(ClassWithStatics.class)
public class mockTest {
@ObjectFactory
public IObjectFactory getObjectFactory() {
return new PowerMockObjectFactory();
}
public static String getString() {
return "111";
}
public static int getInt() {
return 1;
}
@Test
public void test() throws Exception {
PowerMockito.mockStatic(ClassWithStatics.class);
PowerMockito.when(ClassWithStatics.getString()).thenReturn("999");
System.out.println("String: " + ClassWithStatics.getString());
}
}
但错误代码是:
失败:测试java.lang.ExceptionInInitializerError at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter。(ConditionalStackTraceFilter.java:17) 在 org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:41) 在 org.mockito.exceptions.base.MockitoException。(MockitoException.java:30) 在 org.mockito.exceptions.misusing.MockitoConfigurationException。(MockitoConfigurationException.java:18) 在 org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:66) 在 org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:24) 在 org.mockito.internal.configuration.plugins.PluginRegistry。(PluginRegistry.java:12) 在 org.mockito.internal.configuration.plugins.Plugins。(Plugins.java:11) 在org.mockito.internal.util.MockUtil。(MockUtil.java:24)