In partnership with

You ask Claude to refactor a component. The code looks clean. You run the app — something's broken.

You prompt it to fix it. Now something else breaks. Three rounds later, you give up and revert everything. (It gets worse when you forgot to commit first.)

TDD saved me from this loop. That's what this post is about.

What is TDD

You write a test that defines the expected behavior before you write the code. Then you write just enough code to make the test pass.

The cycle:

  • Write a test → it fails (Red)

  • Write the minimum code to make it pass (Green)

  • Clean up the code (Refactor)

  • Repeat

Most of us do the opposite — write the code first, then test afterwards. Or never test at all.

Why TDD matters more now

1. It protects your refactors

I've done this more than I'd like to admit: write solid code, refactor it before committing, and introduce a bug I then spend 30 minutes chasing.

With TDD, once the tests exist, you can rename things, restructure, go wild. As long as tests pass, you didn't break the behavior.

2. It's your only reliable safety net with AI

This is the big one. This is why TDD matters more now than five years ago.

Here's what keeps happening: Claude writes good code. I ask for a small refactor. It breaks the feature. I prompt it to fix. Now something else breaks. Three, four, five rounds — I revert everything.

Without TDD, you're stuck in a fix loop. Each prompt introduces new problems. You can't tell what's broken until you run the app and manually check. By round three, you've lost track of what the code was supposed to do.

With TDD, the moment the AI breaks something, the test goes red. You see it immediately. No guessing. No manual checking. No spiral.

I use a TDD skill that enforces this automatically — the AI writes tests first, runs them, then implements. When I ask for a refactor and something breaks, the tests catch it before I even look at the diff.

We now have tools that write code 10x faster and break it 10x faster. TDD is the only thing that keeps up.

3. And yes — it forces you to actually write tests

How many times have you said "I'll add tests later" and never did? TDD removes the excuse. Tests come first. You can't skip what you start with.

Because you verify they fail before writing the code, you know they actually test something real — not a green-by-default placeholder.

How to start

With AI tools

Install a skill that enforces the Red-Green-Refactor cycle so your agent can't skip it.

Two I've used:

  • tdd — this is the one I run daily. It makes Claude write the test, verify it fails, then implement. If the test doesn't fail first, it loops back.

Install one, configure your AI tool to use it by default, and forget about it. The skill handles the discipline.

Without AI tools

Pick one function you're about to write. Before you write it:

  1. Write a test: it should calculate the total price with tax

  2. Run it — it fails. Good.

  3. Write the function. Run it — it passes. Refactor if needed.

One function. One test. That's your entry point.

Conclusion

TDD felt wrong to me at first. Writing tests before the code goes against every instinct.

But last week I merged a refactor at work — nothing dramatic, but tests stayed green and I didn't think twice before hitting merge. That quiet confidence is what sold me.

Pick one feature you're working on this week. Write the test first. If you're using AI tools, install one of the skills above and let it enforce the cycle for you.

Reply

Avatar

or to participate

Keep Reading