我需要使用Mockito/Power Mockito来模拟一个私有方法。我使用的是testng,我在网上看到的大多数示例都是使用PowerMock+Junit - Mocked private method with PowerMock, but underlying method still gets called模拟私有方法
有没有人能给我举个例子,让我使用Power Mockito+testng。我已经找了一段时间了,但到目前为止还没有找到。
发布于 2019-04-29 19:22:14
您可以使用spy,请参阅下面的链接https://www.baeldung.com/powermock-private-method
此外,使用白盒还可以执行此How to mock private methods using Whitebox(org.powermock.reflect)操作
发布于 2015-09-17 10:51:55
下面是PowerMock和PowerMockito的例子,紧接着就是SO:
发布于 2017-09-27 17:53:55
我找到路了。请试试这个
@Test
public void commandEndHandlerTest() throws Exception
{
Method retryClientDetail_privateMethod =yourclass.class.getDeclaredMethod("Your_function_name",null);
retryClientDetail_privateMethod.setAccessible(true);
retryClientDetail_privateMethod.invoke(yourclass.class, null);
}https://stackoverflow.com/questions/32619368
复制相似问题