如何在Java中测试和模拟同一个类中的2个私有方法?

时间:2016-01-01 18:34:57

标签: java unit-testing junit mockito powermock

我的java类有2个私有方法,method1和method2。 method1调用method2。如何使用任何java测试框架同时测试方法1?

编辑问题: 我使用此语法来调用私有方法: Whitebox.invokeMethod(myClass, "myPrivateMethod","myParameter");

" myPrivateMethod"调用另一个私有方法:" anotherPrivateMethod"。我想嘲笑"另一个私人方法"。我通常使用语法来做到这一点: PowerMockito.doReturn("mockedResponse").when(myClass, "anotherPrivateMethod", "anyParameter");

上述组合似乎不起作用。基本上,当我第一次使用PowerMockito来模拟" anotherPrivateMethod"并使用Whitebox调用" myPrivateMethod",模拟无效。我没有得到" mockedResponse"而是实际的" anotherPrivateMethod"被调用。我做错了什么?

0 个答案:

没有答案