[NotAMockException尝试验证静态方法时

问题描述 投票:0回答:1

我正在尝试验证在单元测试中,在某些配置中未调用静态方法。

因此,我正在使用PowerMock(powermock-core:2.0.4powermock-module-junit4:2.0.4)及其Mockito API(powermock-api-mockito2:2.0.4)。

执行时

PowerMockito.mockStatic(MyClass.class);

serviceUnderTest.methodThatShouldNotCallStaticMethod(arg1, arg2); //service not of type MyClass of course

PowerMockito.verifyStatic(MyClass.class, never());
MyClass.staticMethod(any(), any());

在带有]的类中的测试方法上>

@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class})

我收到以下错误:org.mockito.exceptions.misusing.NotAMockException: Argument passed to verify() is of type Class and is not a mock!

我做错了什么以及如何解决?

谢谢

我正在尝试验证在单元测试中,在某些配置中未调用静态方法。因此,我正在使用PowerMock(powermock-core:2.0.4&powermock-module-junit4:2.0.4)及其...

java android unit-testing powermockito
1个回答
0
投票

原来是a Powermock bug ...

© www.soinside.com 2019 - 2024. All rights reserved.