Do I need to focus on testing "public" methods or "private" methods in a JUnit test?
You need to test everything that is part of the API. If you are not using reflection it means public / protected and package level methods.
This is clearly an opinion. But it is based on experience. Let me give my opinion further.
Ideally, you should practice test-driven development. In this practice, you:
- First, write the tests, including the publicly available test subject methods that you want to have. This will help you develop a useful API.
- Then you write enough code to pass the tests. This will leave you with 100% coverage and no extraneous code.
- Then you are refactoring.
Until you get to the refactoring stage, you probably won't even have private methods.
source to share
I doubt you will see a lot of private methods floating around and as they say they will appear in a method where variables should not be changed outside / outside of special circumstances. That being said, the main difference between public and private is accessibility: the private can only be accessed within the class, while the public can be accessed outside the class.
source to share