Write the Test First, Your Test Must Be Able to Fail

I'm pretty new to Test Driven Development and it's the first time I worked on an environment that adheres to its practices. Something I learned today is Write the Test first before you make any changes. This ensures that you know what you're writing your code against, and you make your solution fit the expected behavior, instead of the behavior trying to fit your solution.

I develop and maintain code. I didn't quite know that TDD can be used in the maintenance stage. I thought at first that it was only useful for new, ground up projects but I was wrong. It could also be, or maybe even more useful in maintenance projects. So again, why do you need to write the test first? Because your test must be able to fail if your designed solution is taken out, and pass if you put it back in.

Published 07-20-2009 1:32 AM by lamia
Filed under:

Comments

Monday, July 20, 2009 7:07 PM by cruizer

# re: Write the Test First, Your Test Must Be Able to Fail

yep. if it doesn't fail first, you might think it's working when actually it was just serendipity ;) it should demonstrably fail, then pass; rather than pass now and fail later :P

Thursday, July 23, 2009 12:04 AM by modchip

# re: Write the Test First, Your Test Must Be Able to Fail

Aha! TDD, now I have a clue as to what it is! :P