Skip to main content

So, let me come clean. I wrote a blog post a while back where I basically said that Test Driven Development (TDD) with AI isn’t that great. I was smug, I was sure of myself, and I was… very wrong. 🫠 But hey, growth is about admitting mistakes, right? And here I am, ready to eat my words (with some spicy Cheetos on the side) and tell you why I now think TDD is the only way to develop with AI.

And it all started with a new VSCode extension I stumbled upon called Cline.

Enter Cline: Your AI pair programmer (without the coffee addiction)

If you haven’t heard about Cline, it’s an AI agent that integrates directly into VSCode. Think of it as your slightly overconfident but genuinely helpful coding buddy. Cline doesn’t just spit out code suggestions; it actually understands your context, offers real-time feedback, and can run tests as you code.

Here’s the kicker: It’s like having a TDD coach sitting on your shoulder, whispering, “Are you sure that function works? Maybe write a test first, you chaotic human.”

And it turns out, that’s exactly what I needed. 😅

Why my initial take on TDD with AI sucked

In my previous post (which I won’t link because no one needs to see that trainwreck), I basically argued that using AI for TDD was overkill. I mean, why write tests first when the AI can just generate code for you, right? Let the machine do the heavy lifting!

Yeah, no.

The problem with that approach? AI gets confused. It doesn’t know what you really want unless you give it constant feedback. You have to describe every edge case, every possible input… and at that point, you might as well write the tests first.

Without tests, you’re in this endless loop of:

  1. AI generates code.
  2. You run the code.
  3. It crashes.
  4. You go back to step 1.

Fun? Not really.

How Cline changed the game

The beauty of Cline is that it flips this process on its head. Instead of treating AI like some magical genie that grants your coding wishes, Cline encourages you to treat it like a responsible adult:

  1. Write a test.
  2. Watch as Cline writes the code to pass that test.
  3. Instantly see if it works.
  4. Refactor, rinse, repeat.

No more vague instructions. No more confused AI. Just pure, unadulterated feedback loops.

And because Cline runs the tests immediately, the AI gets instant feedback. It learns faster. It adjusts quicker. It stops making the same dumb mistakes over and over (unlike me in my pre-coffee coding sessions). ☕

The emotional rollercoaster of coding with Cline

I’ll be honest: At first, I felt attacked.

Cline would pop up with suggestions like, “Your test failed. Want me to fix it?” and I’d think, “No, Cline, I want to wallow in my failure, thanks.” But over time, I realized that this instant feedback is exactly what I needed to break out of my bad habits.

Writing tests first felt weird at first, but watching Cline pass those tests in real-time? That was chef’s kiss satisfying. 😌

Why TDD and AI are a perfect match

Here’s the thing: AI doesn’t understand human emotions (yet). It doesn’t care if you’re having a bad day or if your brain is running on 2% battery. It just wants instructions. Clear, precise instructions.

And what’s the clearest way to give instructions? Tests.

When you write a test, you’re basically telling the AI: “Here’s what I expect. Make it happen.” And because the AI gets that feedback instantly, it’s way less likely to go off on some weird tangent.

How to get started with Cline

If you’re curious (and you should be), here’s how to try Cline for yourself:

  1. Download the extension: Cline on the VSCode Marketplace
  2. Set up your project: Make sure you have a test framework in place (Jest, Mocha, whatever floats your boat).
  3. Write your first test: Start simple. Maybe something like:
    test('adds two numbers', () => {
      expect(add(2, 3)).toBe(5);
    });
  4. Watch Cline work its magic: Sit back and let the AI fill in the gaps.

Final thoughts (aka my apology to the TDD gods)

To anyone I misled with my previous anti-TDD rant: I’m sorry. I see the light now. 🙏

Test Driven Development with AI isn’t just a nice-to-have. It’s a game-changer. And tools like Cline make it easier than ever to adopt this approach.

So, go forth and embrace TDD. Let AI be your coding buddy, not your code generator. And if you ever feel like the AI is judging you… well, it probably is. 😈