Lets say I have a class with two public methods and one private method.
The private method is used by both public methods and unit tests that are written against either of the public methods, could cover all lines of the private method.
Also the private method is complex and to cover all its behaviors many test cases are needed.
I could now:
Test the private method with only one of the public methods and leave it out for the other one.
Disadvantages:
- No clear answer, which of the public methods should be used
- If I chose public method 1 to cover the private method, method 2 is not covered at all. So if method 1 changes in some point in future and is not covering all lines of the private method anymore (but method 2 still does) this test gap could not be noticed.
Write double tests - for each public method the same tests
Disadvantage:
- To hard to maintain the tests
Make the private method public
Disadvantage:
- Hurting the encapsulation
How do you treat situations like this?
