Unit tests are about facilitating change!
Yes, tests find errors in the code, and it is nice to know that your code is working when you have delivered. But that is just a fraction of the benefits you get from tests. The biggie is that you can change your code and still be certain that it does what it’s supposed to do.
Code is always evolving. From the first line you write, and never stops. And I don’t just mean that you refactor your functions. That too, obviously, but all the way up to really changing the code, breaking it up and repurposing it totally by reusing what you have, and giving it a new meaning. This is how it has to be. The world around you changes, you learn new things, the customers changes their minds, the architecture you chose form the beginning has started to hold you back, scaling is an issue and so on. You have to change, there’s no two ways about it.
This is an operation that takes time and costs money. You don’t want that, or at least, you want to minimise it as much as possible. Unit-tests does that. It allows you to make changes with confidence, it enables you to use your building blocks in new ways and still have confidence in it doing it right. Without tests you are like wandering in a dark house without any light. But having tests turns on the lights. They make you see the sharp corners before you hit them. So instead of treading carefully, feeling your way, you can move through the living room the way you do at daytime.
That is what tests does. When you change the composition of your functions, the tests tells you whenever you use the code in a bad way, they prevent you from hitting your toe on that table leg.
Now, given that, I think I have to correct myself about what I said in the beginning. I said that tests finds errors and it is nice to know that your code is working. But that is actually the point. Not just to verify that you added instead of subtracted or any of these low-level bugs. But also, to find the bugs in the grander scheme. To know that even if you broke the monolith up into a modular design or if you moved from an on prem SQL server to a database in the cloud, you still get a green light.
The computer will take that load of from your shoulders and just report when you mess up. You can minimize the mind-numbing drudgery of manual testing and put it into coding instead. Cause that’s what we do, we’re developers, aren’t we?