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

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

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

Post 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!
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

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

Post 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.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

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

Post 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:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
Post Reply