python???????
???????????? ???????[ 2013/7/24 15:15:18 ] ????????
????unittest??python???????????????PyUnit??
?????????????????????濪???????????Щ???á?IO??????????????????????????????????????????????????д????????????????
??????????????????????????????????????????????????????????????????????????????“???”?????????????????????豸?е???????????????????????????????????????豸???????????????????????????????????????????豸δ????????????δ????????????????????в??????????????????????Щ?????????????????????????????????????????????????——???????????????????????????????????????????????????????е???????
????????????????
#FileName: ut_target.py
class EqualToZero(Exception): pass
class SplitZero(object):
def splitzero(self?? num):
if num > 0:
return "num is bigger than zero"
elif num < 0:
return "num is smaller than zero"
else:
raise EqualToZero
#FileName: utest.py
from ut_target import SplitZero?? EqualToZero
import unittest
class SzTestCase(unittest.TestCase):
def setUp(self):
print "test start"
def tearDown(self):
print "test stop"
def testSzBig(self):
num = 10
sz = SplitZero()
self.assertEqual(sz.splitzero(num)??
"num is bigger than zero")
def testSzSmall(self):
num = -10
sz = SplitZero()
self.assertEqual(sz.splitzero(num)??
"num is smaller than zero")
def testSzEqual(self):
num = 0
sz = SplitZero()
self.assertRaises(EqualToZero?? sz.splitzero?? num)
if __name__ == "__main__":
unittest.main()
???python utest.py -v
testSzBig (__main__.SzTestCase) ... test start
test stop
ok
testSzEqual (__main__.SzTestCase) ... test start
test stop
ok
testSzSmall (__main__.SzTestCase) ... test start
test stop
ok
----------------------------------------------------------------------
Ran 3 tests in 0.000s
OK
????unittest??????÷???
????1.import unittest
????2.????????????unittest.TestCase???????????
????3.????setUp??tearDown?????????????????????Щ??????????
????4.???????????????????test?????
????5.?????????????????????????棬???????????????????????????????assertEqual??assertRaises?????????ж??????н????????????????
????6.????unittest.main()???????
????7.???????δ??????????????????????????????????????????κζ???????????????-v???????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11