Checking the sequence of calls to private methods in unit testing

I have the following class:

class MyClass { public void doIt() { methodOne(); methodTwo(); methodThree(); } private void methodOne() { // ... } // rest of methods similar... } 

My intention is to verify that calling doIt () will call the metodOne (), methodTwo (), and methodThree () methods in that order.

I use mockito for ridicule. Does anyone know how I can test this scenario?

+1
java junit mockito mocking
source share
2 answers

I hate being human, but: just don't check it. Check the result, side effects, the results are not implementation.

If you really want to ensure the correct order, extract these methods into a separate class and mock them.

+9
source share

As long as your private methods ... well ... private, do not test them. These are implementation details. They can be reorganized without changing the contract of your class. Verify that the results of your public methods are correct.

+3
source share

All Articles