I want you to think how deeply dysfunctional it is for you to be afraid of what you created — Uncle Bob Martin Architecture the Lost Years

When I sit down to some code that I haven’t touched in a while, I hesitate. This is weird; I wrote it, I created it, so why am I afraid of changing it? Because, the code works now and if I change something it might break.

The code doesn’t have to be important, widely used, or complicated to make me afriad, I only need think one thing:

if something breaks the tests won’t tell me!

The tests are my harness and if I don’t trust them, nothing is stopping me from falling. Documentation, manual testing, or trusting the person who wrote the code (which is usually me) are not cures for this fear. The only thing that settles my nerves is knowing that if I break something, my test suite will yell at me.

For me to trust the tests they must fail when the code breaks and pass when the code works. The best way to make sure that test suite satisfies these requirements is to follow the red, green process:

Write a test, make it fail (red) Write the code, make it pass (green)

Making the test fail first ensures that if the code does’t work it will fail. Writing the code second ensures that the code is what makes the test pass. Trusting my test suite removes my fear, and makes me feel slightly less dysfunctional.

Stop fear, write tests.