1.跳过case
import unittest
class TestMethod(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("类执行之前的方法")
@classmethod
def tearDownClass(cls):
print("类执行之后的方法")
def setUp(self):
print('每次方法之前执行')
def tearDown(self):
print('每次方法之后执行')
def test_01(self):
print("1")
def test_02(self):
print("2")
@unittest.skip('test_03')
def test_03(self):
print("3")
if __name__ == '__main__':
unittest.main()
2.管理case顺序
import unittest
class TestMethod(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("类执行之前的方法")
@classmethod
def tearDownClass(cls):
print("类执行之后的方法")
def setUp(self):
print('每次方法之前执行')
def tearDown(self):
print('每次方法之后执行')
def test_01(self):
print("1")
def test_02(self):
print("2")
def test_03(self):
print("3")
if __name__ == '__main__':
#构造用例集
suite = unittest.TestSuite()
#添加用例
suite.addTest(TestMethod('test_03'))
suite.addTest(TestMethod('test_02'))
#实例化runner
runner = unittest.TextTestRunner()
#执行测试
runner.run(suite)
网友评论