我需要使用mockito和powermock模拟一个不带参数的私有void方法。
该方法属于一个间谍实例。
我知道我需要这样做的事实表明代码很糟糕,但我正在处理一个旧项目,将单元测试从一个测试框架转换为另一个测试框架。
如果有人有任何建议,我们将不胜感激。
谢谢你!
到目前为止我已经尝试过这个:
PowerMockito.doNothing().when(Whitebox.invokeMethod(spy,"method",null));
但我收到这个错误:
No method found with name 'method' with parameter types: [ <none> ]
我还没有尝试过 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..
}
..据我所知..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)