File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Agile and Other Processes and the fly likes what does Test Driven Development Means? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Agile and Other Processes
Bookmark "what does Test Driven Development Means?" Watch "what does Test Driven Development Means?" New topic

what does Test Driven Development Means?

sushil bharwani

Joined: Mar 02, 2006
Posts: 26
I have been hearing this "Test Driven Development" from quite a time, People say that we write junit test cases earlier than we write the actual code, I am not sure how does that happens, when we dont have code what do we write test cases for ? also i want to know how to properly use junit in conjction with Agile and XP Programming

Thanks in Advance
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112 has a fair description of TDD, accompanied with some discussion.

Originally posted by sushil bharwani:
when we dont have code what do we write test cases for?

Before you can write code, you need to know what that code should do (otherwise, how would you know what code to write?).

A test case is simply that knowledge expressed in executable code.

Say, for example, that you want to write a factorial function. One thing you know the code should do is that it should return 1 when it is passed 1 as a parameter. So you code that in a test:

assertEquals(1, factorial(1)); // boiler plate code ommitted

Now you have your first test and can start writing production code to make it pass.

Does that help?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
sushil bharwani

Joined: Mar 02, 2006
Posts: 26
I understand what you say , but one doubt you mentioned of : assertEquals(1,factorial(1)); If function factorial does not exists how will my code compile : or do you say that i write all the junit test cases with prototype methods; can you describe me when any requirments comes up for a project ; how should one proceed in for Agile Development Thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Something that doesn't compile counts as a failing test, so yes that's a valid starting point. One trick is to keep the cycle very small. Write one test that fails, write enough code to make it pass, repeat.

Robert Martin's Bowling Game Kata is a neat example of test first coding ... even though the solution is not particularly OO.

Note that there is no notion of writing a whole lot of tests up front. You should have some idea where you're going, but just code one at a time. One time you might write a test and not immediately code the solution is quitting time. It's nice to come in the next morning and have a failing test to remind you where you were.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: what does Test Driven Development Means?
It's not a secret anymore!