← All opinions

Why TDD Still Matters

tddtestingdesign

The most common objection to TDD is "it slows me down." And honestly? In the first hour, it does. But TDD isn't a productivity hack for writing code faster. It's a design discipline that helps you write better code.

Tests as a design tool

When you write the test first, you're forced to think about the interface before the implementation. What does this function take? What does it return? What are the edge cases?

This is design work. The test is just the medium.

// The test tells you what the API should look like
// before you've written a single line of production code
it("returns an empty array when no posts match the tag", () => {
  const result = getPostsByTag("nonexistent");
  expect(result).toEqual([]);
});

The refactoring safety net

The real payoff comes later. When you have a comprehensive test suite, you can refactor with confidence. Rename a function, extract a module, change an implementation detail — if the tests pass, you haven't broken anything.

Without tests, refactoring is a gamble. With tests, it's routine.

Pragmatic TDD

TDD doesn't mean you test everything. It doesn't mean you chase 100% coverage. It means you use tests to drive the design of the code that matters:

  • Business logic — always test-drive this
  • Data transformations — tests catch edge cases you'd miss
  • Glue code — usually not worth testing in isolation
  • UI layout — integration or E2E tests are more valuable here

The goal isn't religious adherence to a process. The goal is software you can change without fear.