DEV Community

Discussion on: Unit tests dos and don'ts

 
farhanrosenborg profile image
farhan

I am fine with testing private functions altough I never had any problems with just testing the public functions and I am doing that for past 4 years.

Your point which says "Imagine a complex public method that abstracts part of its logic into private methods."

I personally try to follow the Rules of Object Calisthenics (gist.github.com/bobuss/6534934), one of which says that Keep all classes less than 50 lines. With small classes it is really easy to see which scenerios need to be tested. If the tiny private method throws an Exception. It will also be thrown in the public function which is going to call that tiny private function, and from there it can be easily tested.

This is my personal opinion, I am just happy to see tests in any code :-)

Thread Thread
 
dakujem profile image
Andrej Rypo

I am just happy to see tests in any code
So so true! 😑