我在其中一个实用程序类中有这行代码
System.setProperty("someProperty", <StringValue>);
当上面的代码行通过测试执行时,我什么也不想发生。我已经用以下注释注释了该类。
@PrepareForTest({KeyStore.class, System.class})
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.management.*", "javax.security.*"})
我尝试使用以下选项不做任何事情:
1. PowerMockito.mockStatic(System.class);
PowerMockito.doNothing().when(System.class, "setProperty", "someProperty", "stringValue");
2. PowerMockito.mockStatic(System.class);
PowerMockito.doNothing().when(System.class, "setProperty", Mockito.any(String.class), Mockito.any(String.class));
3. PowerMockito.mockStatic(System.class);
PowerMockito.doAnswer(new org.mockito.stubbing.Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return null; //does nothing
}
}).when(System.class, "setProperty", "someProperty", "stringValue");
我总是在执行测试时收到以下错误。
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
关于调用System.setProperty时我什么都不做的任何建议。请注意,System是最终类,我们正在调用带有2个参数的静态方法。谢谢!