Re: [Pyunit-interest] Newbie confused by options
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2002-08-08 13:54:03
|
Noah, Both 'runTest()' and 'testXXX()' are fine. Like much of PyUnit, 'runTest()' came originally from JUnit, the idea being that it is the default name for a test method in a TestCase subclass; it allows for a parameterless constructor call, which is convenient for throwaway tests. e.g. >>> class MyTestCase(unittest.TestCase): ... def runTest(self): ... pass ... >>> result = unittest.TestResult() >>> MyTestCase().run(result) >>> result <<class 'unittest.TestResult'> run=1 errors=0 failures=0> In practice PyUnit, like JUnit, encourages the 'testXXX()' style methods because several can be placed in one TestCase subclass, and they can be found automatically by the convenience functions such as 'unittest.makeSuite()' and 'unittest.main()'. And so yes, 'runTest()' is probably redundant these days for practical purposes, and the documentation fails to make that as clear as it should be. Best wishes, -Steve Noah wrote: > > I am unclear on the difference between the runTest() method > and test methods in the form testXXX() (where XXX is replaced by some string). > The PyUnit Website starts by introducing runTest(), but then > almost immediately switches to the form testXXX() for tests. > The TestCase doc string says "test code itself should be placed > in a method named 'runTest'", yet I was able to follow all > the examples on the PyUnit Website while ignoring runTest(). > > It seems that runTest() is redundant since the TestSuite class > will automatically discover methods named in the form testXXX(). > In fact runTest() seems to be limited in functionality because > you cannot use unittest.main() to test a class that only overrides runTest(). > And unittest.TestSuite().makeSuite() likewise does not use runTest(). > > In what circumstance would I want to define runTest() vs. testXXX()? |