Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've actually become a bigger fan of unit testing private methods over time. :shrug:


Yeah - the alternative is often to make your non-test code worse to make it more testable.

Test private methods when you have sufficient behavior in them that it's worth testing in isolation.


This is all there is to it. The dogma around not testing private methods is entirely unconvincing. I have some very complex private methods that it’s just easier to write some thorough unit tests for, and it guarantees the contract my public methods rely on. I really do not see why that is controversial.




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

Search: