Art of Unit Testing (Acceptance Tests)

John Roth newsgroups at jhrothjr.com
Wed Aug 3 10:12:35 EDT 2005


"Christoph Zwerschke" <cito at online.de> wrote in message 
news:dcpt45$64r$1 at online.de...
> Peter Hansen wrote:
>> What's wrong with using Python's existing "global" support, and just 
>> having your test case setUp() call a global setup routine which checks 
>> whether that global setup work has already been done and, if not, does it 
>> once and sets a flag to say that it has now been done?  I've done this 
>> easily in the few cases where I've wanted this behaviour.  It doesn't 
>> seem complex enough to warrant adding to the standard unit test support.
>
> Actually I already thought about doing it that way, but then I thought it 
> is so ugly, there must be a simpler solution ;-)
>
>> If you're going to quote XP rules of thumb, the tests should be 
>> independent and very fast, and if you have a setup code that is taking a 
>> long time, it's likely a "code smell" of some kind, and you should be 
>> fixing the design which prevents you writing these tests with minimal and 
>> quick setup.  Are these really like "acceptance" tests?  If they were 
>> unit tests, they should take only a few minutes to run, total, and you 
>> should be running them all *many* times a day, not twice.
>
> You're right. I think wanting to have a more global initialization 
> indicates that you are acutally not wanting to do a "unit" test, but a 
> more global test of the overall system, something like an acceptance or 
> integration test, i.e. you are trying to abuse unittest for something it 
> was not intended to be used for.
>
> Maybe since unittest is the only testing framework included with the 
> standard lib, people tend to use it for all testing purposes. If you only 
> have a hammer, everything looks like a nail.

An excellent point, even though it's somewhat blunted by the
inclusion of doctest in the core.

Another point to ponder is that the originators of xUnit, Kent
Beck and Erich Gamma, did not intend it to be used for acceptance
testing. That ecological niche is filled by FIT. The Python port of
Fit can be acquired from the file libraries of the FitNessse or
Extremeprogramming Yahoo mailing lists. I'll get it onto the
CheeseShop (what used to be the Python Package Index) one
of these days Real Soon Now. (Arlo gave me a good shove at
Agile2005 in that direction.)

The FIT developers are working on standardizing the specs,
and expensive setups and teardown are definitely on the agenda.
In fact, that's one of my work items...

Unit testing usually does not require expensive setups and teardowns,
at least if you're not working on real tangled legacy code.
Acceptance testing does.

Meanwhile, there's a book and two web sites: fit.c2.com and
www.fitnesse.org to look at.

John Roth
Python Fit
>
> -- Christoph 




More information about the Python-list mailing list