Why is it crucial to write super fast tests?
Testing is mandatory, but slow tests are more harm than good
Testing is mandatory, but slow tests are more harm than good
I only make a diff to the system if I am convinced that I know what I’m doing. But since reality always bats last, more often than not it turns out that I didn’t really know what I was doing.
The trouble is, by the time I realize I didn’t actually know what I was doing, the damage is already done. Oftentimes, it’s too late for me to save face.
Why is that happening? The reason is simple: code-as-text. I make diffs by modifying the text (either in the source code or in the config). And as even little children know, computers don’t understand text. The change made to the text needs to be transformed into something that computers can understand. That transformation takes time, so there is a lag from the moment I make that diff till the moment the computer tries to execute it.
What that boils down to is that we are suffering a delayed feedback. Any time there is a delayed feedback, the quality of our work is compromised. Immediate feedback is the best way to work, but when working with software systems, immediate feedback is impossible.
So, what’s the solution? Tests. When we write a test, we express our expectations. We are saying “I expect this computing machinery to behave in such-and-such way”. We then see that the expectation hasn’t been met (i.e., we run the test and notice that it fails). We then make some modifications to the system (usually by writing a new module, or a few modules, or by modifying the existing modules, or both), and make the test pass. Meaning, the system now meets our expectations.
Why is that important? As we keep making diffs to the system, with each diff we need to learn whether it broke the system or not. And as the number of those tests grow, the feedback is taking longer and longer to arrive.
That is the reason why we always must strive to only write lightning fast tests. Otherwise the feedback starts getting sluggish, and it doesn’t take too long till we decide to stop writing new tests. Then we’re commencing a death march by amassing the technical debt.