The #1 mistake you make when doing TDD

Test-driven development is a simple process. But if you’re not careful, you can waste a lot of time, or even introduce bugs without knowing it.

Have you ever gotten a test passing, only for the code to still be broken? You’re probably making a fundamental mistake in your TDD process.

The good news is, it’s easy to fix

Just be sure to run your test and watch it fail. If you expect it to fail, but it passes, then you’ve done something wrong. You want to find out right away.

I learned this the hard way, years ago. I wrote a test that I expected to fail, but I didn’t run it. I changed the implementation code to make the test pass, and it did. I tried my new feature through the browser… and it didn’t work. I spent over an hour changing the code, trying to get it to work. Eventually I gave up and reverted my changes to the implementation. I ran the test again… and it still passed.

I wasn’t even testing the code I thought I was! That was a real a-ha moment for me. Ever since that day, I always make sure the test fails before I make any changes to the implementation. And I don’t just reason my way through it – I run the test, and watch it fail.

It doesn’t matter how simple the test is

Watch the test fail, even if it’s obvious that it will. Because one day, you’ll be wrong. But if you watch the test fail first, you’ll know right away. And if you really want to step up your TDD game, try predicting how and why the test will fail.

"How do I become a better Ruby developer?"

Blogs, books, and bootcamps all promise to make you a better Ruby developer, but end up confusing you more.

What if you had step-by-step instructions on how to become a better Ruby developer?

Enter your name and email below and I’ll show you how to...

  • get better at Ruby in just five minutes each day
  • use testing, OOP, and refactoring to write professional-level Ruby
  • identify and learn new programming skills quickly