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

>"For me the rule of thumb is if there's some class requiring lots of work to test, I've been lazy."

Unit tests are great, but when they get in the way I always look it as a chicken and egg paradox. Is my simple and easy to maintain code inferior because it is not test friendly? Or is the test friendly alternative inferior because is more complex and harder to maintain?

And this haven't happened to me just with singletons, sometimes unit tests just like to get in your way.



I find the biggest barrier to unit tests is not noticing when it's more appropriate to create a public static function (probably on another class) instead of a private one. If a private method is so complex that you cannot appropriately test it using the public interface, then it really needs to be its own entity.


I could be a bit off base, and to be honest am only now coming to grips with unit testing fully, but I find if something is painful to test my implementation wasn't good to begin with. I'm guessing this is where writing tests first really comes in handy as you have to implement in the right way from the start.




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

Search: