1 # -*- coding: utf-8 -*- 2 3 import unittest 4 5 class Test(unittest.TestCase): 6 @classmethod 7 def setUpClass(cls): 8 print('start') 9 @classmethod 10 def tearDownClass(cls): 11 print("end") 12 def test01(self): 13 print("执行测试用例01") 14 15 def test02(self): 16 print("执行测试用例03") 17 def test03(self): 18 print("执行测试用例02") 19 if __name__ == "__main__": 20 unittest.main()
结果:
Ran 3 tests in 0.000s
OK
Launching unittests with arguments python -m unittest D:/tes1t/test/case/baidu/test_01.py in D: es1t estcaseaidu
start执行测试用例01
执行测试用例03
执行测试用例02
end
Process finished with exit code 0
setUp前置和tearDown后置只执行了一次,这样就可以在只执行一次的情况下执行内部的多个用例(打开浏览器和关闭浏览器的动作)