3 ms·
You must not have inherited many ugly codebases. I would love to write tests for the codebase I currently work in but it just doesn't make sense. Everything wo
by rement 6y ago
You must not have inherited many ugly codebases.
I would love to write tests for the codebase I currently work in but it just doesn't make sense. Everything works for the most part (not really but the business people are happy) so they is no way we can convince the hire ups that writing tests is beneficial.
- wenc 6y agoActually migrating legacy (ugly) codebases is where writing tests is helpful. The tests are the invariants -- they help you preserve functionality while you shift the code underneath. You can rewrite ugly code without worrying about botching anything downstream.
- nickm12 6y agoAgreed, but... often these ugly codebases are also very difficult to write tests for, because the code isn't well-factored, there are large functions which combine lots of unrelated behaviors, etc. etc. I inherited a codebase of this type two years ago. It was only 10k sloc of Python but some of the worst code I've ever worked with—of course it had no tests either. Retroactively writing tests for the existing code made no sense—half the behavior wasn't worth preserving. What I wound up doing was slowly refactor as I worked on things, writing a new component (with tests) and replacing bits of the legacy code. I also added linting and typechecking and now the code is not gorgeous, but it's serviceable and a lot less buggy. In retrospect it might have been better to just rewrite it from scratch, architected for testing, but it's difficult to be certain. I think it was probably better for the team to see the codebase improved piecemeal bit by bit, even if it took longer.
- wenc 6y agoI hear you. Testing is but one of many tools needed to fix ugly codebases. It's no panacea for sure.