1

I want to check if a private method is called inside my tested method. Since the method is private I use this :

  PowerMockito.verifyPrivate(societeHome, times(1)).invoke("createFournisseurSocieteBinding", Mockito.any());

This test ALWAYS passes, I could write times(1000) and it still works ! So I put a breakpoint in the method createFournisseurSocieteBinding and it is called when I launch the verifyPrivate method !! How is this the wanted behaviour since I want to check if my TESTED method does call the createFournisseurSocieteBinding and not the verifyPrivate method.

Is there a way to check if my tested method calls an inner method which is private ? It works fine with non-private methods with Mockito.verify(...)

Sly
  • 51
  • 5
  • In UntTests we verify *public observable behavior* which is *return values* and *method calls on dependencies*. `private` methods are *implementation details* which we do not test. The reason is that implementation details may change while the *behavior* of the unit shall *not* change (aka: *refactoring*) In that case we don't want the test to change because this is the only way to *guarantee* the behavior is still the same. – Timothy Truckle Feb 21 '18 at 12:19
  • Okay but then what is the method `verifyPrivate` from PowerMockito for ? I read the documentation and as I understood it, it should do the same thing as the `verify` method from Mockito which it clearly doesn't. – Sly Feb 21 '18 at 16:31

0 Answers0