python中unittest单元测试框架-加载测试用例、运行测试用例、生成测试报告-通过模块加载用例
发布时间:2020-05-25 01:22:22 所属栏目:Python 来源:互联网
导读:import os import unittest # 创建suite对象 suite = unittest.TestSuite() # 第二种方法:通过loader来加载用例-通过模块加载用例 fr
import os
import unittest
# 创建suite对象
suite = unittest.TestSuite()
# 第二种方法:通过loader来加载用例-通过模块加载用例
from class1228_unittest_loader.test_cases import test_setup
loader = unittest.TestLoader()
suite.addTest(loader.loadTestsFromModule(test_setup))
# 创建存放测试报告的文件夹-report
dir = os.path.dirname(os.path.abspath(__file__))
report_path = os.path.join(dir,'report')
if not os.path.exists(report_path):
os.mkdir(report_path)
file_path = os.path.join(report_path,'test_result.txt')
with open(file_path,"w") as f:
# 初始化运行器, 是以普通文本生成测试报告 TextTestRunner
runner = unittest.TextTestRunner(f,verbosity=2)
# 运行测试用例
runner.run(suite) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
