python中unittest單元測試框架-加載測試用例、運行測試用例、生成測試報告-通過discover加載某個文件夾下的所有用例


import os
import unittest
import HTMLTestRunnerNew

# 1、初始化testloader
testloader = unittest.TestLoader()

# 2、查找測試用例,加載
dir = os.path.dirname(os.path.abspath(__file__))
case_dir = os.path.join(dir, 'test_cases')

suite = testloader.discover(case_dir)


# 創建存放測試報告的文件夾-report
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.html')

with open(file_path, "wb+") as f:
    # 初始化運行期, 是以普通文本生成測試報告 TextTestRunner
    runner = HTMLTestRunnerNew.HTMLTestRunner(stream=f, title='API測試報告', description='執行用例詳情', tester='奔奔')
    # 運行測試用例
    runner.run(suite)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM