Hacker News new | past | comments | ask | show | jobs | submit login
Is it OK to change code for the sake of testing? (understandlegacycode.com)
1 point by asicsp on May 8, 2021 | hide | past | favorite | 1 comment



I would say, yes.

There are heated discussions about tests but in my opinion tests are crucial for maintainability of code in an automated fashion. Can you do without them, probably yes if the repo is small enough and most devs know most of what's going on. Once it grows large enough that most devs can't keep it all in their heads, tests help a lot. Not a panacea, but definitely help guard against unintended mistakes due to lack of understanding.

With that preamble, changing code to be more testable is great so long as it doesn't involve adding code just for tests like "if (debug) {".




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

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

Search: