import unittest
class TestOrder(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("所有用例之前执行")
def setUp(self):
print("每个用例开始前执行")
def tearDown(self):
print("每个用例结束后执行")
@classmethod
def tearDownClass(cls):
print("所有用例之后执行")
def testA(self):
'''用例A'''
print("用例A")
self.assertTrue(True)
def testB(self):
'''用例B'''
print("用例B")
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()
执行顺序
setUpClass->setUp->testA->tearDown->setUp->testB>tearDown->tearDownClass
用例之间按用例名称ASCII码的顺序加载,数字与字母顺序为09,AZ,a~z, 所以testA会在testB之前运行。