UnitTest自动化测试框架生成自动化测试报告

发表于:2022-6-17 09:33

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Redrose2100    来源:稀土掘金

  1、HTMLTestRunner安装
  使用如下命令安装即可:
  pip install caterpillar-HTMLTestRunner

  2、HTMLTestRunner使用
  比如test01.py中测试用例代码如下:
  import unittest
  class TestDemo01(unittest.TestCase):
      def test_01(self):
          print("in test_01...")
      def test_02(self):
          print("in test_02...")
      def test_03(self):
          print("in test_03...")

  测试套文件中代码如下:
  import unittest
  import os
  from demo.test01 import TestDemo01
  from HTMLTestRunner import HTMLTestRunner
  report_title="测试报告标题"
  report_desc="测试报告描述"
  report_path="./report"
  report_file=os.path.join(report_path,"report.html")
  if not os.path.exists(report_path):
      os.mkdir(report_path)
  suite = unittest.TestSuite()
  suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDemo01))
  with open(report_file ,"wb") as report:
      runner = HTMLTestRunner(stream=report, title=report_title, description=report_desc)
      runner.run(suite)

  执行完成后生成测试报告用浏览器打开如下:

  本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号