How to organize test cases with PyUnit

Roy Smith roy at panix.com
Sun Jul 7 23:46:09 EDT 2002


Peter Hansen <peter at engcorp.com> wrote:
> Rename the runTest()
> method to start with the text "test", and then change the __main__
> content to be simply 'unittest.main()' instead of the dictEntries.run
> that you have.

OK, that seemed to work, even though I'm still not sure I understand all 
the subtleties of what's going on, and what role all the various classes 
(TestCase, TestSuite, TestResult, TestLoader, etc) play.

After writing just a few test cases, I've come to the conclusion that 
the names of the individual test methods are meaningless, except to 
dictate what order the tests run in.  I've taken to just naming them 
test101, test102, etc (leaving plenty of room in the numbering system to 
insert additional tests).  The doc strings seem to be the place to get 
creative, since those are what's printed.

I don't see it mentioned in the documentation, but it seems that if you 
make multiple subclasses of unittest.TestCase, the names of those 
classes get sorted and run in order as well.  So, I'm inclined to adopt 
the same scheme of just naming the classes class101, etc.



More information about the Python-list mailing list