zoukankan      html  css  js  c++  java
  • BeautifulReport--适用于unittest自动化测试的可视化报告

    安装:

      因为是由大神分享的,可以直接在github<https://github.com/TesterlifeRaymond/BeautifulReport>上下载 git clone git@github.com:TesterlifeRaymond/BeautifulReport.git  download后,需要把包放到 D:python3.6.5Libsite-packages 目录下,以备调用;

    使用:

      和HTMLTestRunner.py在运行case上稍有不同

    import os
    import time
    import unittest
    from BeautifulReport import BeautifulReport
    from common.logger import Log
    # from common.HTMLTestRunnerCN import HTMLTestRunner
    from common import readConfig
    
    now = time.strftime('%Y-%m-%d %H-%M-%S')
    
    
    def add_case(case_path):
        """加载所有的测试用例"""
        discover = unittest.defaultTestLoader.discover(case_path, pattern='test*.py', top_level_dir=None)  # 定义discover方法的参数
        Log().info('测试用例:%s' % discover)
        # HTMLTestRunner
        # testUnit = unittest.TestSuite()
        # discover方法筛选出来的用例,循环添加到测试套件中
        # for test_suite in discover:
        #     for test_case in test_suite:
        #         testUnit.addTests(test_case)
        # return testUnit
    
        # BeautifulReport
        return discover
    
    
    def run_case(all_case, report_path):
        """执行所有测试用例,并把结果写入报告"""
        # HTMLTestRunner
        # report_abspath = os.path.join(report_path, now + 'report.html')
        # fp = open(report_abspath, 'wb')
        # runner = HTMLTestRunner(stream=fp, verbosity=2, title=readConfig.title, description='用例执行情况:')
        # runner.run(all_case)  # 调用add_case函数返回值
    
        # BeautifulReport
        result = BeautifulReport(all_case)
        result.report(filename=now + 'report.html', description=readConfig.title, log_path=report_path)
        Log().info('执行用例,生成HTML报告!')
    
    if __name__ == '__main__':
      case_path = os.path.abspath(os.path.dirname(__file__)) + '\case'
      all_case = add_case(case_path)
      # 生成报告测试路径
      # report_path = os.path.abspath(os.path.dirname(__file__)) + '/report'
      report_path = os.path.abspath(os.path.dirname(__file__)) + '\report'
      run_case(all_case, report_path)

      不需要再添加case,直接返回获取到的所有用例即可;

    html报告:

      稍微修改了下生成的报告,增加了 用例错误 的展示和返回顶部的按钮;

      因为是跑的接口,所以没有使用  BeautifulReport 的截图功能,有机会再试... 

    问题:

      在 用例描述 那里会显示:dict() -> new empty dictionary dict ,看了下,好像是在获取用例函数的文档字符串时,返回的就是这个,暂时没找到原因,只能先去掉了...有知道的大佬请指点下...

    ------------------小小的分割线-------------------------

    dict() -> new empty dictionary dict 错误: ddt降级到1.1.2版本即可;

  • 相关阅读:
    raspbian设置locale
    docker redis
    consul开发部署集群
    自动更新ssh登录的key到远程主机
    docker官方脚本阿里云镜像
    nodejs中国镜像
    github修改hosts加速
    docker容器更新总是自动重启
    webstrom不显示右边的竖线,代码结构线
    _mssql.c:266:22: fatal error: sqlfront.h: No such file or directory
  • 原文地址:https://www.cnblogs.com/changqing8023/p/9572181.html
Copyright © 2011-2022 走看看