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版本即可;

  • 相关阅读:
    注释神器
    Q币直充-迅银渠道商(php 面向对象类)
    rsync 同步多台服务器项目目录
    wdcp 打开网页显示 Apache 2 Test Page powered by CentOS -- 来自辉哥博客
    elasticsearch批量修改,批量更新某个字段
    Ik分词器没有使用---------elasticsearch-analysis-ik 5.6.3分词问题
    spring-boot-starter-data-elasticsearch 整合elasticsearch 5.x详解
    FastJson--SerializerFeature.PrettyFormat 如何实现格式化源码查看
    由Premature end of Content-Length delimited message body因发的问题排查
    JVM的YoungGC日志查看
  • 原文地址:https://www.cnblogs.com/changqing8023/p/9572181.html
Copyright © 2011-2022 走看看