vendredi 1 janvier 2016

Using Powermock to test and mock private methods simultaneously in the same class in Java

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("mockResponse").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