DEV Community

Discussion on: What is the difference between public, protected, and private in Java?

Collapse
 
tacsiazuma profile image
Krisztian Papp

In my opinion, making anything protected from private to make it testable is generally a bad practice. You shouldn’t test private parts of the class, just the public (or package private if it is meant to be used just internally) API (which still includes private methods). If its hard to test because of the logic in these private methods, then its a design issue and you might want to extract that part from the class.

Collapse
 
skittishsloth profile image
Matthew Cory

One thing I'll add is that you should be able to test the private logic via the public interface anyways. IOW, if you can get complete coverage of your public interface and your private logic isn't tested, then you either don't really have full coverage or your private logic isn't accessible anyways (and get rid of it).