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を介して実行しています.レガシーコードにはたくさんのメソッドがあります...
誰かがアイデアを持っていて、私は公式のチュートを試しましたが、この簡単なテストを機能させることはできません