Art of Unit Testing

Jeff Shannon jeff at ccvcorp.com
Fri Aug 17 14:32:49 EDT 2001


Paul Moore wrote:

> On Fri, 17 Aug 2001 15:41:12 +0200, "robin and jim" <robinjim at earthlink.net>
> wrote:
>
> >You are quite correct (according to my version of the documentation -- and
> >in my experience with using the tool); setUp and tearDown are called for
> >each test so you always start and end from a known state. <wink>
>
> I'd argue that if you want to do setup and teardown actions for each
> individual test, you can code the actions in the test. But there's no way to
> code a setup for a series of tests. For example, in a database application,
> you may want to create a connection in setUp(), run a series of queries in
> tests, and then close the connection in tearDown(). Creating and closing a
> connection per test could well be an unacceptable overhead. To my way of
> thinking, this is the common case (of setup/teardown actions), and should be
> easy to do. Setup and teardown actions which have such a low overhead as to be
> OK to do for each test would seem to be less common. (Indeed, that's how the
> docs describe setUp and tearDown, as high-overhead actions, IIRC.)

Well, the alternative argument could be that, if you don't need to setup and
teardown in between various tests, then they could be coded as subtests of a
single, larger test...  OTOH, if you *do* have high setup/teardown overhead, which
*does* require being redone for each test, then coding it each time would be a
pain.  Lumping subtests together is easier than multiple copies of
setup/teardown...

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list