[TIP] Doctest or unitest?

Grig Gheorghiu grig at gheorghiu.net
Sat Mar 3 09:29:18 PST 2007


This is the question that Michael Foord asks in his latest blog post:

http://www.voidspace.org.uk/python/weblog/arch_d7_2007_03_03.shtml#e652

To me, they represent 2 different styles of testing: procedural
(unittest) vs. declarative (doctest). I had an aha-type moment during
PyCon when I realized that both Fit/Fitnesse and doctest are very
similar in that they represent 'example-driven testing' (I didn't
invent the term example-driven, Brian Marick did). You specify inputs
with expected outputs, in the form of examples. 

With unittest, and the other frameworks based on it or similar to it,
there's more procedural stuff: do this, do that, then assert that it
happened (FitNesse also supports this with DoFixture fixtures).

I find both styles useful. The other value of Fit/Fitnesse and doctest
is that they serve as 'executable documentation'. 

Grig



More information about the testing-in-python mailing list