What Tests Are Actually For

The usual reason given is 'to prove the code works'. That is the least valuable thing tests do, because you already checked it by hand once and it worked.

The real value arrives later. Tests are what let you change code you no longer remember writing, and know within seconds whether you broke something. Without them, every change to a system past a certain size is a gamble, and the rational response to a gamble is to stop changing things. That is how a codebase becomes one nobody dares touch.

Four things a test suite buys.

Refactoring. You can restructure freely because the tests say whether behavior changed.

A record of intent. A test is a statement of what the code is supposed to do, in a form that cannot go out of date silently.

Bugs that stay fixed. A test written when you fix something means it cannot come back quietly.

Faster feedback. Seconds instead of clicking through the interface.

✦ The honest cost

Tests are code. They take time to write, they need maintaining, and a bad suite is worse than none: slow, flaky, and testing implementation rather than behavior, so every refactor breaks fifty of them and people start deleting tests to make the build pass. That failure mode is common and this course is largely about avoiding it.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: What Deserves a Test →
← Back