Page 1 of 1

Why isn't this a good example of Test Driven Development?

Posted: Fri Feb 08, 2008 10:09 am
by Skittlewidth
I'm taking my first steps into Unit Testing and the like so I've just been reading up on some of the recommended links here and doing some simple tutorials. The following linked tutorial is in C# but ignore that, its the principles I'm interested in.

http://www.nunit.org/index.php?p=quickStart&r=2.4.6

The introduction says "it's been pointed out that this isn't a good example of Test-Driven Development". Can someone tell me what's up with it, cos it fails to follow up on that statement. I have been through this Quick Start and think I've started to understand what TDD is all about but I worry I'm going to get it all wrong if I start writing my own basic tests based on what I did here!

Re: Why isn't this a good example of Test Driven Development?

Posted: Fri Feb 08, 2008 10:28 am
by Maugrim_The_Reaper
Easy, it provides an implementation before any tests are written. In TDD one always writes the test first, ensures it fails, then implements it, and finally ensures it passes.

The logic behind the first failure is simply to prevent any tests showing false-positives by passing. If a new test passes right away, then it's obviously not testing the right thing, or you just uncovered another smoke signal from a possible bug.

Re: Why isn't this a good example of Test Driven Development?

Posted: Fri Feb 08, 2008 10:42 am
by Skittlewidth
Thanks, I think I understand...maybe...

So another tutorial I did that ran the first test on an empty function on an empty class before writing any code was a bit nearer the mark? Or have I missed the point? :oops:

Re: Why isn't this a good example of Test Driven Development?

Posted: Fri Feb 08, 2008 2:00 pm
by Christopher
No, you got it. Test Driven means just what is says -- the tests are what steers your development. So you write the test first, then you develop code to meet that test. You can also write tests after coding (because tests are good things) but that is just Unit Testing, not TDD.