Python??????????????????????
???????????? ???????[ 2017/3/3 10:51:31 ] ????????Python ?????????
????1??????
??????????????????????????????????????????????????
????· ????????????????????
????· ???????????
????· ????????????????
??????????????? ????????? ???Χ???? ???????? ???????
?????????????????????? python ??????????????????????????????????????????????????Щ???????????????????????????????????????????? IDE ????????????????н???
???????????ï¿¡?
????1?????????????????????Ч?????
????2??????????????????к????????????????
????????????? ????????? ??????????????????????????????Google???????????????????????????????????
????“?????????????????г??????????????????????????????е? ??????????? ?????????????????е? ??????????? ”??
?????????????????????????????????????????????????????????????????????????????????????????????????
????2??PyUnit??????
??????? python ??????????????????????????? pyunit ?????????????????
???????2????????????????? pyunit ?????????????????????Щ???????????????????????????????????????????????д????д????б?????????
????python?????????? PyUnit??????????? Java ?????μ????????? JUnit ?? Python ???????汾?????????????? Kent Beck ?? JUnit ???????
????unittest??????????
????· ????????????
????· ?????е?????????? ????(setup) ?? ???(shutdown) ?????
????· ????????????collections??????????????????????
????· ?????е?????????????????ж???????
???????????????unittest?????????????????
????· ????????test fixture??
?????????????????????????Щ????????????磺?????????????????????????????????????
????· ??????????test case??
??????????????????????С???????????Щ?????????????????в?????
????· ?????????test suite??
?????? ???????? ???? ???????????? ??????????????????????????????????????????е????????
????· ???????????test runner??
??????????????????л?????????????????????Щ??ν??棬??????????????Щ??????????????????????????????????????????
????3?????????
??????????????????????? basic_demo.py??
# coding:utf-8
"""
????????????????? basic_demo.py
"""
__author__ = 'zheng'
import unittest
class TestStringMethods(unittest.TestCase):
def setUp(self):
print 'init by setUp...'
def tearDown(self):
print 'end by tearDown...'
def test_upper(self):
self.assertEqual('foo'.upper()?? 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
self.assertTrue('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split()?? ['hello'?? 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
?????????????????????????????????????????????
????1??????????????
????2??????????????
????3??????????????
??????????д????????в??????????????????????????????????????о?????????????????????? ????????????????????????????????????????????????
????· ?????? ????? unittest.TestCase
????· ????????????????? ??????????
????· ??????????????????? test_ ???
????· ?????????????????е??????????? setUp??tearDown????
???????????????д????
src git:(master) python basic_demo.py
init by setUp...
Fend by tearDown...
init by setUp...
end by tearDown...
.init by setUp...
end by tearDown...
.
======================================================================
FAIL: test_isupper (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "basic_demo.py"?? line 24?? in test_isupper
self.assertTrue('Foo'.isupper())
AssertionError: False is not true
----------------------------------------------------------------------
Ran 3 tests in 0.001s
FAILED (failures=1)
src git:(master)
???????????????? main ??????????????????????????е??????????????????????????檔???????????ú??????Щ???????????????Щ???????????к??????????????????????????????????????????м?????γ?????????
if __name__ == '__main__':
# unittest.main()
# ??????????
test_cases = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
# ??ò???????????????????
test_suit = unittest.TestSuite()
test_suit.addTests(test_cases)
# ???в???????????????????
test_result = unittest.TextTestRunner(verbosity=2).run(test_suit)
#??????????
print("testsRun:%s" % test_result.testsRun)
print("failures:%s" % len(test_result.failures))
print("errors:%s" % len(test_result.errors))
print("skipped:%s" % len(test_result.skipped))
???????к????????????
src git:(master) python basic_demo.py
test_isupper (__main__.TestStringMethods) ... init by setUp...
FAIL
end by tearDown...
test_split (__main__.TestStringMethods) ... init by setUp...
end by tearDown...
ok
test_upper (__main__.TestStringMethods) ... init by setUp...
end by tearDown...
ok
======================================================================
FAIL: test_isupper (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "basic_demo.py"?? line 23?? in test_isupper
self.assertTrue('Foo'.isupper())
AssertionError: False is not true
----------------------------------------------------------------------
Ran 3 tests in 0.001s
FAILED (failures=1)
testsRun:3
failures:1
errors:0
skipped:0
??????????????????????????????????????????Щ?????????β?????е?????????Щ?????????????????????????????????????????????????????γ??????????????·?????Щ?????????????????????????????
??????????????????????????????????????????????????????????
????· ????????test fixture??
??????setUp?????????????????????tearDown?????????
????· ??????????test case??
???????TestCase????????????????????????????
????· ?????????test suite??
???????TestSuite??
????· ???????????test runner??
???????TextTestRunner??
??????
???·???
??????????????????
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