Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Do you test private methods? (stackoverflow.com)
3 points by xatax on Aug 22, 2010 | hide | past | favorite | 1 comment



I realize that submitting StackOverflow questions here has become a bit of a "karma whore" (to borrow a phrase from reddit) trend lately, but I stumbled upon this question earlier and thought it might make for good discussion here.

As an extremely junior developer, I don't presume to know everything (or even much) about development, but I thought testing private methods was pretty much a given.

The argument in the accepted answer that "[a] private method is an implementation detail that should be hidden to the users of the class" seems to miss the point, IMO. I mean, an entire codebase is an "implementation detail that should be hidden from the (end) user" but it doesn't mean we shouldn't test it.

I think of unit tests as being tests of the smallest testable chunks of code, to ensure that every atomic piece of an application works to spec. By all means, test the public interface, but I think testing the pieces that make up that interface is important too.

That's two cents from a guy that has never done these sorts of tests anyway, so take it for what it's worth.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: