GeeCON Prague 2014*
The moose likes Agile and Other Processes and the fly likes how to start on a WEB Project with TDD 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 "how to start on a WEB Project with TDD" Watch "how to start on a WEB Project with TDD" New topic
Author

how to start on a WEB Project with TDD

sushil bharwani
Greenhorn

Joined: Mar 02, 2006
Posts: 26
Thanks Friends,

I am a WEB Developer and going to start on a new WEB Project , I want TDD with this project but i m not sure abt what and how much time does TDD requires how much of my time out of entire project would be required for writing test cases , what all things i should consider while planning resource and time for this project and how will i write test cases for my servlets jsps struts javascripts web interfaces and all I know i m asking many questions all at one time but i know somebody surely have answers
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
If you are new to TDD, I'd advise to start by testing your business logic (which should be well decoupled from any web-specific logic). After you get used to the general rhythm of TDD, you can start to tackle more advanced topics, such as testing servlets, JSPs etc. pp.

In general, you can expect to spend as much time writing test code as you spend writing production code. On the other hand, you can expect to spend much less time debugging and revisiting code that you thought was already "done". It is also likely that you will find that your design becomes simpler and easier to extend.

All in all, most people find that coming up with high quality code takes less time using TDD than without TDD.

You certainly should plan to take significantly longer while you are *learning* to do TDD. A good book - or preferably some hands-on training, for example as nowadays provided on most conferences - will likely help with that.


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
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
My process on web projects has tended to be very similar to the paradigm described in Lasse Koskela's Test Driven book -- ie what he's termed an "Acceptance TDD" cycle wrapping the regular TDD cycle.

If you're not familiar with TDD at all, I wouldn't recommend this approach initially, as you'll have to tackle a lot of "hard/annoying" configuration issues up front.

But to give an example of how I start a project:
I'll start with an acceptance test like

(Note: there is a fair bit of "magic" hidden in the base class, setting up JWebUnit and DbUnit, etc)

With this failing acceptance test, I'll then dive into the unit tests needed to work towards a working implementation. I'm working in Struts 2, so there's no magic needed to test Actions, so often I'll start there, but sometimes I'll go to either the service or domain layers...

This first acceptance test actually covers a lot of ground (which is why it can be a very hard first hurdle)
a) I can build my source, start a container, deploy my app, in an automated manner. (When first starting out, I don't mind using the start/stop/redeploy options in my IDE, but IMO it needs to be automated before starting on the second acceptance test)
b) I have the web-framework hooked up with a mapping for the index page of the site configured
c) I have the database hooked up (since the list of items is being pulled from that and the ability to inject test data into it

Typically my next acceptance test would cover that a request for "/" gets redirected to the same welcome page. With the third acceptance test driving my security infrastructure -- asserting that a request for a protected resources gets redirected to a log-in page. Which of course leads into a suite of acceptance tests covering login/logout/account creation/password resets/etc... Once that's accomplished moving onto the real business of the web application takes over, but I'll know I have my infrastructure in place and its surrounded by the two sets of tests.
sushil bharwani
Greenhorn

Joined: Mar 02, 2006
Posts: 26
Thanks a lot just wanted to add two more questions

when using junit how do people actually prepare their test data :

By test data i mean if i have a add(a,b) method this a,b can have several values; what is the way of testing my method with various values of a and b do we create a test database how do we do negative testing.How do we plan test data.

Another question is on a confusion of using setup and teardown methods

setup is used to intialize something for a test case

if i have two test methods

say testAdd and testDatabaseconfiguration these two methods cannot have same setup and teardown things than how can i actually use one setup and teardown configuration for all my testMethods

Thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by sushil bharwani:
when using junit how do people actually prepare their test data :

By test data i mean if i have a add(a,b) method this a,b can have several values; what is the way of testing my method with various values of a and b do we create a test database how do we do negative testing.How do we plan test data.


It sounds to me like you are trying to think too much in advance. With TDD, you don't do that.

For the example above, what would be the very first test you would write?



Another question is on a confusion of using setup and teardown methods

setup is used to intialize something for a test case

if i have two test methods

say testAdd and testDatabaseconfiguration these two methods cannot have same setup and teardown things than how can i actually use one setup and teardown configuration for all my testMethods


You don't. See http://tools.clrstream.com/~gerard/Testcase%20Class%20per%20Fixture.html
sushil bharwani
Greenhorn

Joined: Mar 02, 2006
Posts: 26
Thanks Ilja

I just wanted to know how do we plan test Data and how do we do negative testing when using junit do we have some links where i can study it
 
GeeCON Prague 2014
 
subject: how to start on a WEB Project with TDD