Where did you learn to unit test? How did you learn?

Roy Smith roy at panix.com
Thu May 1 19:41:26 EDT 2003


"David Broadwell" <anti-spam.dbroadwell at mindspring.com> wrote:
> For the less educated here(spreading the bug early);  What exactly is a unit
> test?

A unit test is something which tests an atomic unit of code for correct 
operation.  This is opposed to system testing, where you test a whole 
application at one time.  Not everybody agrees on what an "atomic unit" 
is.  Some people think of a function as a unit, some people think of a 
class as a unit.  I don't think there's any one correct answer to that.

Unit tests are typically devised and run by the person (or team) who 
writes the code.  System test is much more likely to be done by a 
separate test team, working from design specs.

> How does the investment payoff?

The longer a bug remains undetected, the more expensive it is to fix.  
Depending on whose numbers you want to believe, it's 10 times as 
expensive to fix a bug during system test than it is to fix it during 
unit test.  Add another factor of 10 if it escapes from system test and 
gets to the customer.  So, the payoff is that more bugs get caught and 
fixed earlier when it doesn't cost a lot to do so.  Often, you have a 
finite amount of system test resources available, so if you give the 
system test guys better stuff, they can devote more effort to finding 
different kinds of bugs that unit testing would never discover (i.e. 
poor interactions between modules or components).

Another good thing about unit tests is they they are completely 
automated, so it's easy to run the entire test suite often (like every 
day, or every time you make a change).  This provides an important 
regression test capability to make sure future modifications don't break 
current code.




More information about the Python-list mailing list