import unittest #定义测试类Test,父类为unittest.TestCase
class Test(unittest.TestCase):
def setUp(self):
print("Test.setUp")
def test_One(self):
print("Test.test_One")
def tearDown(self):
print("Test.tearDown")
class Test1(unittest.TestCase):
def setUp(self):
print("Test1.setUp")
def test_One(self):
print("Test1.test_One")
def tearDown(self):
print("Test1.tearDown")
if __name__=='__main__':
suite=unittest.TestSuite() #实例化测试套件
#将测试用例加载到测试套件中
suite.addTest(Test('test_One'))
suite.addTest(Test1('test_One'))
#实例化TextTestRunner类
#使用run()方法运行测试套件(即运行测试套件中的所有用例)
runner=unittest.TextTestRunner()
runner.run(suite)