Reputation: 1
Is there a way to test private/ protected methods in JUnit5?
In JUnit 4 testing private methods may be an indication that those methods should be moved into another class to promote reusability. And for protected methods tests should be placed in the same package as the classes under test.
What is the case in JUnit5?
Upvotes: 0
Views: 132
Reputation: 5341
In JUnit 4 testing private methods may be an indication that those methods should be moved into another class to promote reusability.
I’d argue that this statement holds without the first three words. There’s no difference between JUnit 4 and 5 in this regard; even more, the testing framework has nothing to do with it at all.
So I recommend that you proceed equally: Either test the private method indirectly through the public interface or extract it to a place where it can be exercised independently.
Upvotes: 1