zoukankan      html  css  js  c++  java
  • python中unittest单元测试框架-加载测试用例、运行测试用例、生成测试报告-通过模块加载用例

    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)
  • 相关阅读:
    第二周作业
    第一次作业
    第0次作业
    第一次的作业
    第0次作业
    第三次作业
    %f使用时的注意事项
    关于c++停止工作
    第二次作业
    第一次作业
  • 原文地址:https://www.cnblogs.com/benben-wu/p/12131498.html
Copyright © 2011-2022 走看看