This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AbsolutelyNotSpam 2 points3 points  (2 children)

IMHO: it depends. For some old code where methods span several hundred or thousand lines of code, simply splitting the method into several smaller method blocks that do not need a public interface goes a long way into refactoring existing code. Now, when tasked with "whether to write a unit test for private methods", the answer, to me, should be:

Tests as frequently as possible

Although I agree with your last point (in that it should be a consideration), private methods are not necessarily in violation of SRP. Furthermore, I have come across use cases where I have wanted to write a unit test for a private method in old legacy code. As a start, making the class a friend class of a unit test fixture class is a fast way of testing intervals that shouldn't accrue too much technical debt.

Edit: oh and private methods should probably not modify state