【发布时间】:2018-01-30 02:40:29
【问题描述】:
我正在使用PowerMockito 和spy 来模拟私有方法:
final SomeClass someClass = new SomeClass();
final SomeClass spy = PowerMockito.spy(someClass);
PowerMickito.doReturn("someValue", spy, "privateMethod1");
final String response = Whitebox.invokeMethod(spy, "anotherPrivateMethod");
// I can now verify `response` is of the correct data
// But I also want to verify `privateMethod1` was called x times or so
我不知道如何验证我的方法是否被调用了 x 次。
旁注
只创建我所有的私有方法protected 然后在我的测试类中扩展该类并这样做会更好吗?
【问题讨论】:
标签: java junit powermock powermockito