Python中使用BeautifulReport形成测试报告教程
pyton中使用BeautifulReport形成测试报告需要先安装BeautifulReport模块
打开cmd窗口输入 pip install BeautifulReport
下载完成之后在Python中导包验证是否完成
from BeautifulReport import BeautifulReport
在Python中实现BeautifulReport报告主要分三步
1、 组装测试套件: 把要执行的测试用例放入到测试套件中
2、 准备测试报告文件(路径+报告文件名.html) 报告文件名: 系统时间+项目名.html
3、批量执行测试用例,把结果写入到测试报告文件中。
class TestRun:
#定义一个方法:来批量执行测试用例,并且把结果写入到测试报告中
def run_cases(self):
#1. 组装测试套件: 把要执行的测试用例放入到测试套件中
dir_path = os.path.dirname(__file__) #获取当前文件所在的位置
case_path = os.path.join(dir_path,"..","test_case")
tao_jian = unittest.defaultTestLoader.discover(case_path,pattern="*case.py")#pattern要执行的测试用例
#2. 准备测试报告文件(路径+报告文件名.html) 报告文件名: 系统时间+项目名.html
report_path = os.path.join(dir_path,"..","..","reports")
sys_time = strftime("%Y%m%d%H%M%S")
report_name = sys_time+"xxx.html"
#3. 批量执行测试用例,把结果写入到测试报告文件中。
BeautifulReport(tao_jian).report(description="测试报告描述",filename=report_name,report_dir=report_path)