public class TestStatic {
public static int methodstatic(){
return 3;
}
}
@Test
@PrepareForTest({TestStatic.class})
public class TestStaticTest extends PowerMockTestCase {
public void testMethodstatic() throws Exception {
PowerMockito.mock(TestStatic.class);
Mockito.when(TestStatic.methodstatic()).thenReturn(5);
PowerMockito.verifyStatic();
assertThat("dff",TestStatic.methodstatic()==5);
}
@ObjectFactory
public IObjectFactory getObjectFactory() {
return new org.powermock.modules.testng.PowerMockObjectFactory();
}
}
例外:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
我通过 Intellij 运行它,遗留代码有很多方法......
有人有想法,我通过了官方教程,并不意味着让这个简单的测试工作