我有一个测试,该测试可以验证使用某些参数调用了静态方法
@PowerMockIgnore({"javax.management.*"})
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyUtil.class})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MyTest {
@Test
public void Test() {
PowerMockito.mockStatic(MyUtil.class);
when(MyUtil.doStaticMethod(any(), any())).thenReturn("value");
// do test
...
verifyStatic(MyUtil.class, times(1));
MyUtil.doStaticMethod("a", "b");
}
}
如果使用参数“ a”和“ b”调用一次该方法,则效果很好,但是如果我将验证更改为times(2)
或"aa", "b"
而不是得到测试失败错误,我得到< / p>
org.mockito.exceptions.misusing.NotAMockException: Argument should be a mock, but is: class java.lang.Class
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:182)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:164)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:141)
at com.mycompany.project.MyUtil.doStaticMethod(S3ServiceUtil.java)
at ...
我正在使用powermock 1.7.4和mockito 2.8.9,并为最终课程安装了嘲笑制造者内联。我什么都找不到,有什么主意吗?谢谢!