Comments by "Brent Jacobs" (@br3nto) on "The ONLY REASON To Unit Test" video.
-
Yeah…. But tests are there for other reasons…. Im currently refactoring a rather old codebase. Quite a lot of deeply nested code, many conditionals, lots of coupling, the multiple responsibility principle was applied to everything. I can’t just inject dependencies or mocks, because the system wasn’t built in a way to do that or for that to be useful. There’s also no unit or integrations tests. There are some limited regression tests. Im trying to refactor that code so I can modernise it and upgrade it. But it’s really really easy to accidentally break functionality… every change has subtle effects. I have to maintain all functionality, even the bugs, because who knows what relies on that bug. I have to build tests to verify the existing functionality first, so that I can then make the changes I need to make, and then use the tests to verify my changes didn’t break anything. Had the tests been there in the first place, the app probably wouldn’t have been written the way it was, and I wouldn’t have to do double the work because some previous develop didn’t take time to write tests. Though back when this was written, unit testing was less common… so that dev get a pass. Write tests! Future devs (possible even future you) will thank you!
4