[melbourne-pug] Unit Testing (Following up TDD presentation)

Mike Dewhirst miked at dewhirst.com.au
Thu Sep 1 13:28:38 CEST 2005


Maurice Ling wrote:
> Hi all,
> 
> Following from Bruce's presentation, I've been using TDD mainly on the 
> new codes I'm writing. Are there any advice from the group for handling 
> old codes that I've written but needs modification?

Old stuff which works doesn't need unit tests UNLESS you intend to 
modify it.

If I was going to modify something old I would probably start again from 
scratch because I can't stand looking at my own old code. But if I was 
forced to I would try to break it into chunks of manageable size and 
keep it working - sort of an integration test suite - which produces 
known outputs with test data.

I would then ...

1. find a bit of functionality I wanted to modify
2. define an interface via which that function can be used
3. write the TDD unit tests which fit that interface
4. write unit-tested software in a new class
5. modify the old code to call the new class for that functionality
6. see if it all still works together with the test data

My bottom line is that it is almost impossible to retrofit unit tests to 
old code. Not because it can't be done but because when you sit down and 
look at it you get very dejected. It is very hard. It would generally be 
easier and quicker to write new unit-tested software.

Wrong way - go back :)

Cheers

Mike


> Thanks
> Maurice
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pug at python.org
> http://mail.python.org/mailman/listinfo/melbourne-pug



More information about the melbourne-pug mailing list