我试图验证在使用 powerMockito 1.6.4 测试服务方法时从未调用过静态方法
我关注了This answer做同样的事情。
以下是我的代码。
@RunWith ( PowerMockRunner.class)
@PrepareForTest ( MyClass.class)
@PowerMockIgnore ( "javax.net.ssl.*")
public class SomeTests
{
@Test
public void testMyMethodIsNotCalled() throws Exception
{
PowerMockito.mockStatic(MyClass.class);
underTest.testMethod();
PowerMockito.verifyStatic(Mockito.never());
MyClass.myMethod(Mockito.any());
}
}
我现在面临的问题是,MyClass.myMethod(Mockito.any());
调用真正的myMethod
并给出nullPointerException。
我的假设是 MyClass.myMethod(Mockito.any());
与 PowerMockito.verifyStatic(Mockito.never());
一起使用,以便指定静态方法待验证。
我错过了什么吗?
最佳答案
你还必须模拟静态方法行为
即像这样的东西
PowerMockito.mockStatic(NameOfClass.class);
expect( NameOfClass.nameOfMethod((URL)Mockito.any(),Mockito.anyString())).andReturn(actualOutput);
关于java - Power mockito 验证静态调用真实方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58743855/