Java – OOP design – Private modifier
I thought I knew when to use the private keyword Encapsulation is the reason for this, so I try to keep all methods as confidential as possible
I just wrote an article about testing and was told that using reflection for testing on my private methods is a bad idea. It's bad code design Why? The fact that my key code is hidden / encapsulated is a good thing and should not be tested, because this is really the key to my public code?
Solution
Good testing attempts to achieve high code path coverage, so yes, testing private methods is a good thing But why do you call them directly with reflection? The fact that these methods are private usually indicates the existence of public / protected methods that use them Therefore, testing public methods means testing private methods