Reputation: 371
are most of the JUnit test written for public methods or private methods? Which do I need to focus on if I have not so much time?
Upvotes: 3
Views: 272
Reputation: 18459
You test the behavior of classes. Start with public method. If you cover all states of the object most likely you would cover the private methods. Aim for 100% state coverage ( just a mark. not really achievable in practical cases)
Upvotes: 1
Reputation: 2804
I doubt you are going to see a whole lot of private methods floating around, that being said, they will show up in a method where the variables involved should not be modified externally/outside of very specific circumstances. That being said, the main difference between public and private is accessibility: private can only be accessed within the class, whereas public can be accessed outside of the class.
Upvotes: 0
Reputation: 38978
You should to test everything that forms part of the API. Unless you're using reflection, this means the public/protected and package level methods.
Clearly, this is opinion. But it is one based on experience. Let me take my opinion further.
Ideally, you should practice test-driven development. In this practice you:
Until you get to the refactoring stage, you probably won't even have any private methods.
Upvotes: 4
Reputation: 15673
Depends on your goal of testing. Ideally you want to test all of them at 100% coverage :)
Upvotes: 0