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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>