Why Test Software? TL;DR Summary
Last updated:
- If you didn't test the code, you don't know if it works
- If there are no tests, you can't refactor
- Tests are documentation (for humans and AI)
- Tests protect your flows against changes by peers
See all posts related to testing here: Entries by Tag: testing
Minimum Viable Post (MVP ) to send to your colleague who isn't sure whether tests are really needed.
If you didn't test the code, you don't know if it works
As simple as that.
If it's not tested, you don't know if it works. You should assume it doesn't!
"But this piece of logic is so simple, there's no need to test it." Yes, there is. We all make mistakes and we should by default distrust any untested code.
"But I tested the function manually, running a script". Ok, you saw the function working once, but nothing guarantees it'll keep working as it's updated.
If there are no tests, you can't refactor
If there are no tests (unit, integration, etc) for some piece of logic, nobody can refactor the source code and be confident that it still works.
If the code can't be refactored, it will slowly gain entropy, rot away and eventually become unmanageable.
Tests are documentation (for humans and AI)
Especially for complex logic, it's often hard to understand what exactly how or why some piece of code works.
Tests instantiate a piece of code with an actual use case, and that makes its intent and purpose clearer.
Tests protect your flows against changes by peers
"If you liked it then you shoulda put a test on it
" Adapted from Beyoncé
In addition to refactoring, software is by definition a shared asset. You may own a given feature or flow, but they depend on shared functions and components.
You cannot complain if somebody changes a function and your particular feature breaks because it implicitly depended on an untested behavior of that function. You should have added a test to guarantee that your particular use-case is kept covered by any changes to that function.