Two kids playing with a carousel at a playground.

I see unit tests as the playground where code learns to behave.

We want reusable code. Being easily unit testable is proof that the code can work in two contexts. As soon as you use the unit outside the test, you are already reusing it.

Design pressure from driving development with tests is like the training kids get from play. We teach the code how to interact with others, experiment with interfaces, boundaries and naming.

When we have code that works well in a unit test (and no, if you need a fancy testing framework the code is not behaving well enough ) we can let it play with the rest of the production code.

If it is a pain to test, it will be a pain to use, maintain and debug. So play with the code a bit first, it will be worth it.

Related texts

A single frosted leaf with clear contours and veins.

TDD in the context of writing code to be read

Wunder Baum hanging from a car window (Known as Little Trees in most English-speaking countries)

Wunderbaum testing