??????????????????
?????????????????Python???????????????????????е????????????????????д???????????assert???????????????????????
??????????????????????????в??????Python??????????????“.pyo"???????????????assert??佫??????????ò?????????????á?
?????????Щ??????Python????????????д?????assert_??????????TestCase??????????????????assert????? ??????????????????y??鷳????????????????????С??
????def runTest(self):
????self.assert_(self.widget.size() == (100??100)?? "size is wrong")
?????????TestCase????????failIf??failUnless??????????
????def runTest(self):
????self.failIf(self.widget.size() <> (100??100))
????????????????????????fail??????ò???????????
????def runTest(self):
????...
????if not hasattr(something?? "blah"):
????self.fail("blah missing")
????# or just 'self.fail()'
?????????????
???????????????????????????????????????????????????????????
????TestCase??????????assertEqual??assertNotEqual?????????????????????????????????failUnlessEqual ?? failIfEqual????
????def testSomething(self):
????self.widget.resize(100??100)
????self.assertEqual(self.widget.size?? (100??100))
??????????
??????????????????????????????????????????????????????????????????????????????
????def runTest(self):
????try:
????self.widget.resize(-1??-1)
????except ValueError:
????pass
????else:
????fail("expected a ValueError")
?????????????????????????????????????????????????????TestCase?????assertRaises??????????????????????????ó?????“except”????е??????????????????????????????????????????
????def runTest(self):
????self.assertRaises(ValueError?? self.widget.resize?? -1?? -1)
???????PyUnit???t???????
?????Щ???????????е?????????????TestCase?????????PyUnit?????С?
????????PyUnit???????FunctionTestCase?????TestCase?????????????????в???????????ú?????????????????????????
???????????2????????
????def testSomething():
????something = makeSomething()
????assert something.name is not None
????...
??????????????????????????????????
????testcase = unittest.FunctionTestCase(testSomething)
????????и???????ú????????????????????????????????2?????
????testcase = unittest.FunctionTestCase(testSomething??
????setUp=makeSomethingDB??
????tearDown=deleteSomethingDB)
??????JPython??Jython?????PyUnit
???????PyUnit??????“C” Python????д?????????????Jython??дPyUnit??????????????Java??Jython??????????Jython??дJ(rèn)Unit??????????PyUnit????????????Jython???汾??Jython 1.0??1.1Э???????
?????????Java??????TK GUI????????PyUnit?????TKinter??GUI???????Jython?1????????????????????????????????????
???????Jython?????PyUnit???????????????????C Python????????‘traceback.py'?? 'linecache.py'?? 'stat.py' ?? 'getopt.py'??????????JPython???????λ?????????????κ?C Python?????????????Щ??????????????C Python 1.5.x?汾????????????????汾Python???????
?????????????????????C Python????????д???PyUnit???????
???????????
????????
?????μ? "??????????????" ??????????????
??????????
???????????????????й????б???????????????????traceback???????????棬?????????????????????н??????????????????????????????????????????δ????GUI TestRunner???????????????????????е?????????????
??????????????????????????????????????????????????????????Щ???????????????????????????????????????????????????????????????????????????????????????
???????????
?????????????Python?????????????????????????????????·????????????????????????email????????URL??????????????????У?????????????????????
???????д??????????????????????????????????????????????????????????????????????????
????δ?????
????????????δ????????TK GUI??IDLE IDE????????????????
????????????????????????鸚?????????????PyUnit?????????????????????????????????Щ?????????????飬?????????????????????????д?????б?д??
??????????????
?????????????????????????????????????á?
?????????????????????????棻?????????????????????????С????????б???????????????????д?????PyUnit????????????????????????
??????л
????Many thanks to Guido and his disciples for the Python language. In tribute?? I have written the following haiku (or 'pyku'?? if you will):
????Guido van Rossum
????'Gawky Dutchman' gave birth to
????Beautiful Python
????I gratefully acknowledge the work of Kent Beck and Erich Gamma for their work on JUnit?? which made the design of PyUnit a no-brainer.
????Thanks also to Tim Voght; I discovered after I had implemented PyUnit that he had also implemented a 'pyunit' module as part of his 'PyWiki' WikiWikiWeb clone. He graciously gave me the go-ahead to submit my version to the community at large.
????Many thanks to those who have written to me with suggestions and questions. I've tried to add appropriate credits in the CHANGES file in the download package.
????Particular thanks to J¨|r?me Marant?? who packaged PyUnit for Debian.