Mockito / Powermockito模拟私有空方法

我需要使用mockito和powermock来模拟一个不使用参数的私有void方法。

该方法属于间谍的实例。

我知道我需要这样做的事实表明代码不好但我正在使用一个旧项目将unit testing从一个测试框架转换到另一个测试框架。

如果有人有任何建议,将不胜感激。

谢谢!

到目前为止,我试过这个:

PowerMockito.doNothing().when(Whitebox.invokeMethod(spy,"method",null)); 

但我得到这个错误:

 No method found with name 'method' with parameter types: [  ] 

我没有尝试过Whitebox(它附带Powermock),但尝试类似:

 @RunWith(PowerMockRunner.class) @PrepareForTest(MyClass.class) public class MyClassTest { private MyClass myClass; @Before public void setup() { myClass = PowerMockito.spy(new MyClass()); PowerMockito.doNothing().when(myClass, "myPrivateMethod"); } //Tests.. } 

..据我记得..