???????????????????Щcase????????ж??????е?case????????д???run.py????????????е???????????????????????????£?
????import unittest
????from test_sort import TestSort
????if __name__=='__main__':
????suite=unittest.TestSuite()
????#suite.addTest(TestSort('test_quick_sort_1')) #????????est_quick_sort_1????case
????#suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSort)) #??????????????
????suite.addTest(unittest.makeSuite(TestSort)) #???TestSort???е?????case
????runner=unittest.TextTestRunner(verbosity=2) #????2??????????????
????runner.run(suite)
??????????????????????????????????setUp??tearDown(???case??????????)??setUpClass??tearDownClass(???????????????)??????д????????????????????case???????????????????????????case?????????setUpClass?н?????????????tearDownClass??д????????????case?????????????Щ????????????????У??????????setUp??д?Щ??????????????????к???tearDown?????????????????????????????
?????÷?????????test_sort.py??????′????????
import unittest
from sort import Sort
class TestSort(unittest.TestCase):
@classmethod
def setUpClass(cls):
print 'this is setupclass'
def setUp(self):
print 'this is setup'
def test_bubble_sort_1(self):
arr=[]
self.assertEquals([]??Sort.bubble_sort(arr))
def test_quick_sort_4(self):
arr=(15??12??36??22??1??7??18)
self.assertEquals(sorted(arr)??Sort.quick_sort(arr))
def tearDown(self):
print 'this is teardown'
@classmethod
def tearDownClass(cls):
print 'this is teardownclass'
???run.pyЧ?????£?
>>>
this is setupclass
test_bubble_sort_1 (test_sort.TestSort) ... this is setup
this is teardown
ok
test_quick_sort_4 (test_sort.TestSort) ... this is setup
this is teardown
ok
this is teardownclass
----------------------------------------------------------------------
Ran 2 tests in 0.043s
OK
>>>