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

Skip Montanaro skip at pobox.com
Tue Apr 29 16:59:25 CEST 2003

    -c> I've noticed in my development that Python programmers (in general)
    -c> write more unit tests than their java counterparts.  If I download a
    -c> project off of jakarta.apache.org, it very rarely has unit tests. 
    -c> However, when I download a python module, it frequently has unit
    -c> tests.

That's (I think) because:

    * In general writing Python is easier than writing Java.  That holds
      true for test code as well as application code.  Note that Perl
      packages tend to also have plenty of test cases.

    * The PythonLabs folks set an excellent example.  Take a look at the
      Lib/test directory in your Python distribution.  The tests there are a
      mixture of the newer unittest-based stuff and a couple older schemes.

    -c> What advice can you offer on spreading the testing bug around?  

Bugs.  When you discover a bug, write a test case which tickles the bug.
Then fix the bug and use the test case to demonstrate that the bug is gone.
It's simple and objective.

    -c> What success stories do you have?  

Python itself works as a pretty good success story.  The presence of a large
suite of test cases increases confidence that new code doesn't break things,
and when it does, that fact is generally discovered very quickly.

    -c> Any insight you can offer would be appreciated.

Lead by example.  Create a test subdirectory in your source code repository
and start writing test cases.  Use those test cases to demonstrate that your
code functions as required.  


More information about the Python-list mailing list