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

Harry George hgg9140 at cola2.ca.boeing.com
Tue Apr 29 15:38:38 EDT 2003


blunck at gst.com (Christopher Blunck) writes:

> Hi all-
> 
> This is my second generic question posted to c.l.p (the first was 'How
> many of you are Extreme Programmers?') but it seems like a somewhat
> appropriate discussion for the group.
> 
> I've noticed in my development that Python programmers (in general)
> write more unit tests than their java counterparts.  If I download a
> project off of jakarta.apache.org, it very rarely has unit tests. 
> However, when I download a python module, it frequently has unit
> tests.
> 
> I'm in a position where I'm trying to spread the testing bug to my
> team.  It's remarkable to watch folks who were once viciously opposed
> to unit testing adopt it  as being absolutely critical during
> application development.  While this is encouraging, it is far from
> the common case, and I'd like to improve that.
> 
> What advice can you offer on spreading the testing bug around?  
> 
> What success stories do you have?  
> 
> What practices did you follow?  
> 
> Did you beat people over the head with it until they wised up?  
> 
> Were you softer in your approach?  
> 
> What worked?  
> 
> What were the long term implications?
> 
> How quickly did unit testing catch on?
> 
> Or did unit testing never catch on?
> 
> 
> 
> Any insight you can offer would be appreciated.
> 
> 
> -c

First, I start each project with my mkpythonproj, which automatically
generates the test dirs and the unittest scripts:
  http://www.seanet.com/~hgg9140/comp/index.html

Next, I try to push all testing to this style:
  a) Either use input files or hardcoded testcases to 
     generate a test result file
  b) Manually check that it is correct, then promote it to the "oracle"
  c) Compare to the known-good oracle.  This is done in a "check" method
     used by all testcases, and of course uses std naming conventions.
        #--compare to oracle---
        oraclename='testdata/oracle_%s.xml' % testname
        assert filecmp.cmp(outname,oraclename)

Quite often the "test result file" is an XML rendition of a complex
internal memory state.  We do roundtrip:
  a) Generate the memory state (e.g., by processing several input files)
  b) Output the XML
  c) Kill the top-of-tree, to get a fresh start
  d) Read the XML back in, to fully rebuild the memory state
  e) Output again to XML.
  f) Compare this 2nd XML to the known-good oracle.

[Hmmm...   I think I'll go update mkpythonproj this weekend.]

Given the framework, it becomes easy to add new cases or even new
modules to the testsuite.  And regression testing becomes easier than
manually scanning printouts (plus of course faster and less
errorprone).

We have about 30 programmers using this approach.  You have to have a
"true believer" set it up and add the first few testcases for the
specific project.  Then ramp up a newbie (or at least new to unittest)
to run the regression tests while doing mods.  Thne handhold while
he/she generates a new testcase.   


-- 
harry.g.george at boeing.com
6-6M31 Knowledge Management
Phone: (425) 294-8757




More information about the Python-list mailing list