unittest框架用HTMLTestRunner或BeautifulReport生成网页测试报告

https://blog.csdn.net/sun_8923/article/details/108912523
上一篇学习是unittest框架,今日学用HTMLTestRunner或BeautifulReport生成网页测试报告

import unittest,time
import HTMLTestRunner

# 用HTMLTestRunner生成网页测试报告
current_time = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime())
test_dir = './cases/'
discover = unittest.defaultTestLoader.discover(test_dir, pattern='Test*.py')
report_name= './report/'+current_time+'.html'
report_title = 'BaiDu测试报告'
report_desc= 'TestReport generated by HTMLTestRunner.'
with open(report_name,'wb')as f:
    runner = HTMLTestRunner.HTMLTestRunner(stream=f, title=report_title,description= report_desc, verbosity=2)
    runner.run(discover)

unittest框架用HTMLTestRunner或BeautifulReport生成网页测试报告_第1张图片

import unittest,time
from BeautifulReport import BeautifulReport

current_time = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime())
test_dir = './cases/'
discover = unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
report_desc = 'TestReport generated by BeautifulReport'
report_dir = './report/'
report_name= current_time+'.html'
result = BeautifulReport(discover)
result.report(filename= report_name, description= report_desc, report_dir= report_dir)

unittest框架用HTMLTestRunner或BeautifulReport生成网页测试报告_第2张图片
unittest框架用HTMLTestRunner或BeautifulReport生成网页测试报告_第3张图片

你可能感兴趣的:(笔记)