java - Powermock counts more than actually call when verify -


is bug of powermock or i'm doing sth wrong?

the following test should pass, failed with:

trackbugpartialmockcountmore(com.xiaomi.finddevice.test.testcase.powermockbug) org.mockito.exceptions.verification.toomanyactualinvocations:  classtomock.foo(); wanted 1 time: -> @ com.xiaomi.finddevice.test.testcase.powermockbug.trackbugpartialmockcountmore(powermockbug.java:24) 3 times. undesired invocation: -> @ com.xiaomi.finddevice.test.testcase.powermockbug.trackbugpartialmockcountmore(powermockbug.java:22) 

when remove @preparefortest(classtomock.class), every thing goes , test passed.

import org.junit.ignore; import org.junit.test; import org.junit.runner.runwith; import org.powermock.core.classloader.annotations.preparefortest; import org.powermock.modules.junit4.powermockrunner;  import static org.mockito.mockito.verify; import static org.powermock.api.mockito.powermockito.mock; import static org.powermock.api.mockito.powermockito.when;  @runwith(powermockrunner.class) @preparefortest(classtomock.class) public class powermockbug {      @test     public void trackbugpartialmockcountmore() {         classtomock mock = mock(classtomock.class);         when(mock.foo()).thencallrealmethod();          mock.foo();          verify(mock).foo();     }  }   class classtomock {     public int foo() { return 0x10; } } 

version: powermock-mockito-junit-1.6.3

in example don't need use powermock because not mocking/spying final or static method. can safely remove both @runwith , @preparefortest annotations. mockito needed purposes


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -