[TIP] Test Driven Development

Michael Foord fuzzyman at voidspace.org.uk
Sun Mar 4 13:49:05 PST 2007

Michał Kwiatkowski wrote:
> On 3/3/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>> I'm interested in how many people on this list are doing test driven
>> development ?
> I tend to use TDD with doctests and TED (mentioned by Grig) with
> unittest. For some reason doctest is so easy to set up that I can
> define a behaviour and API for a function/method without thinking
> about it. 

I'd never even considered doctests for TDD.

As others have said though, doctests tend to get kind of ugly when you 
do exception handling.

They also seem perfectly designed for copying and pasting an interactive 
session *after* the code is implemented. I always resent typing '>>>'. :-)

> Unittests usually require some mock-shmock-setup-ing, so I
> usually implement the function, test it manually and write automated
> test for it later (or never :( ). In some sense doctest encourages me
> to do the right thing, so it is probably better tool than unittest (of
> course YMMV).

Unittest feels right to me, but you have to put some work in to keep 
your tests readable.

> I try to unit test most of the code and write functional tests when I
> really need them (i.e. things which unit tests won't catch).
We have a different philosophy with functional tests. Functional tests 
are for high level 'test the features'.

Our unit tests should cover everything that the functional tests do and 
more. If a functional test exposes a bug that isn't covered by unit 
tests, then we slap ourselves and write a unit test quickly. Happens a 
lot though. :-)


> Cheers,
> mk

More information about the testing-in-python mailing list