日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

unittest多线程生成报告-----BeautifulReport

發(fā)布時間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 unittest多线程生成报告-----BeautifulReport 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

原文地址https://www.cnblogs.com/yoyoketang/p/8404204.html

前言

selenium多線程跑用例,這個前面一篇已經(jīng)解決了,如何生成一個測試報告這個是難點(diǎn),剛好在github上有個大神分享了BeautifulReport,完美的結(jié)合起來,就能生成報告了。

環(huán)境必備:

  • python3.6 : BeautifulReport不支持2.7
  • tomorrow : pip install tomorrow安裝
  • BeautifulReport : github下載后放到/Lib/site-packages/目錄下

BeautifulReport

1.BeautifulReport下載地址:BeautifulReport

2.下載方法:

  • 方法一 會使用git的直接用git下載到本地
  • git clone https://github.com/TesterlifeRaymond/BeautifulReport

  • 方法二 點(diǎn)Clone or Download按鈕,Download ZIP就能下載到本地了

?

2.單個測試腳本test_a.py參考

# coding:utf-8import unittest from selenium import webdriver import timeclass Testaa(unittest.TestCase):u'''測試用例a的集合'''@classmethoddef setUpClass(cls):cls.driver = webdriver.Firefox()def setUp(self):self.driver.get("https://www.cnblogs.com/yoyoketang/")def test_01(self):u'''用例1:用例1的操作步驟'''t = self.driver.titleprint(t)self.assertIn("悠悠", t)def test_02(self):u'''用例2:用例2的操作步驟'''t = self.driver.titleprint(t)self.assertIn("悠悠", t)def test_03(self):u'''用例3:用例3的操作步驟'''t = self.driver.titleprint(t)self.assertIn("悠悠", t)@classmethoddef tearDownClass(cls):cls.driver.quit()if __name__ == "__main__":unittest.main()

?

3.run_all代碼

# coding=utf-8 import unittest from BeautifulReport import BeautifulReport import os from tomorrow import threads# 獲取路徑 curpath = os.path.dirname(os.path.realpath(__file__)) casepath = os.path.join(curpath, "case") if not os.path.exists(casepath):print("測試用例需放到‘case’文件目錄下")os.mkdir(casepath) reportpath = os.path.join(curpath, "report") if not os.path.exists(reportpath): os.mkdir(reportpath)def add_case(case_path=casepath, rule="test*.py"):'''加載所有的測試用例'''discover = unittest.defaultTestLoader.discover(case_path,pattern=rule,top_level_dir=None)return discover@threads(3) def run(test_suit):result = BeautifulReport(test_suit)result.report(filename='report.html', description='測試deafult報告', log_path='report')if __name__ == "__main__":# 用例集合cases = add_case()print(cases)for i in cases:print(i)run(i)

4.報告效果圖

備注:BeautifulReport是某大神在github分享的框架,這里借花獻(xiàn)佛了,更多使用方法參考地址:https://github.com/TesterlifeRaymond/BeautifulReport

BeautifulReport下載地址:
https://pan.baidu.com/disk/home#/all?vmode=list&path=%2Fpython%E6%8E%A5%E5%8F%A3%E8%87%AA%E5%8A%A8%E5%8C%96--unittest--beautifulReport

轉(zhuǎn)載于:https://www.cnblogs.com/111testing/p/10060900.html

總結(jié)

以上是生活随笔為你收集整理的unittest多线程生成报告-----BeautifulReport的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。