This question already has an answer here:
My java class has 2 private methods, method1 and method2. method1 invokes method2. How can I test method1 at the same time mocking method2 using any of the java testing frameworks?
Edited question: I am using this syntax to invoke a private method: Whitebox.invokeMethod(myClass, "myPrivateMethod","myParameter");
"myPrivateMethod" invokes another private method: "anotherPrivateMethod". I would like to mock "anotherPrivateMethod". I usually do this using syntax: PowerMockito.doReturn("mockedResponse").when(myClass, "anotherPrivateMethod", "anyParameter");
The combination above does not seem to work. Basically, when I first use PowerMockito to mock "anotherPrivateMethod" and use Whitebox to invoke the "myPrivateMethod", the mock is not working. I am not getting "mockedResponse" but instead the actual "anotherPrivateMethod" is getting invoked. What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire