import unittest
from base.serach_case import CassDemo
# 创建测试用例套件
suite = unittest.TestSuite()
# ----------------------------------
# 添加测试用例,方式一(逐个添加测试用例名称来运行)
# suite.addTest(CassDemo('test_04'))
# suite.addTest(CassDemo('test_03'))
# runner = unittest.TextTestRunner()
# runner.run(suite)
# ----------------------------------
# 添加测试用例,方式二(将所有类下面的用例名称组合成为集合运行)
# cases1 = [CassDemo('test_01')]
# suite.addTest(cases1)
# runner = unittest.TextTestRunner()
# runner.run(suite)
# ----------------------------------
# 添加测试用例,方式三(按照文件的位置读取泛指文件名称文件来运行)
# test_dir = '../base'
# discover = unittest.defaultTestLoader.discover(start_dir=test_dir, pattern='*_case.py')
# 基于runner运行测试套件
# runner = unittest.TextTestRunner()
# runner.run(discover)
# ----------------------------------
# 添加测试用例,方式四(unittest函数下的方法来获取类名称来运行下面的所有测试用例)
# suite.addTest(unittest.TestLoader().loadTestsFromTestCase(CassDemo))
# runner = unittest.TextTestRunner()
# runner.run(suite)
# 添加测试用例,方式五(unittest函数下的方法来获取文件名+包名+类名)
suite.addTests(unittest.TestLoader().loadTestsFromName('base.serach_case.CassDemo'))
runner = unittest.TextTestRunner()
runner.run(suite)
文章源自玩技e族-https://www.playezu.com/26296.html