加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python中unittest单元测试框架-加载测试用例、运行测试用例、生

发布时间:2020-12-17 17:06:02 所属栏目:Python 来源:网络整理
导读:import os import unittest # 创建suite对象 suite = unittest.TestSuite() # 第二种方法:通过loader来加载用例-通过模块加载用例 from class1228_unittest_loader.test_cases import test_setuploader = unittest.TestLoader()suite.addTest(loader.loadTes
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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读