Class to be tested
public class ClassUnderTest {
public void functionA() {
functionB();
functionC();
}
private void functionB() {
}
private void functionC() {
}
}
@RunWith(PowerMockRunner.class)
public class TestClass {
@Test
public void testFunctionA() throws Exception {
ClassUnderTest classUnderTest = PowerMockito.spy(new ClassUnderTest());
classUnderTest.functionA();
PowerMockito.verifyPrivate(classUnderTest).invoke("functionB");
PowerMockito.verifyPrivate(classUnderTest).invoke("functionC");
}
}
在執行測試類,我發現了以下錯誤,
org.mockito.exceptions.misusing.UnfinishedVerificationException:
Missing method call for verify(mock) here:
-> at org.powermock.api.mockito.PowerMockito.verifyPrivate(PowerMockito.java:312)
Example of correct verification:
verify(mock).doSomething()
Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
如果一個驗證評論則測試案例工作正常。
你好@bharanitharan兩行,你有什麼辦法解決?我有同樣的問題... – Abdelhafid