前言

使用HTMLTestRunner需要在python安装目录Lib\site-packages文件下添加Lib\site-packages.py文件, 目前我使用的python版本是Python 3.6.1,HTMLTestRunner.py文件分享:链接:https://pan.baidu.com/s/1ffdhVivVCoZHMbVJwx6GWg提取码:n9vx

生成测试报告

1、创建一个testreport.py

import HTMLTestRunner
import unittest

class Testreport(unittest.TestCase):
    def test01(self):
        self.assertEqual("aa","aa")
    def test02(self):
        self.assertEqual(1+2,3)
if __name__ == '__main__':
    testsuit = unittest.TestSuite()
    testsuit.addTest(Testreport("test01"))
    testsuit.addTest(Testreport("test02"))
    fp = open("a.html","wb")#wb是转换成二进制的只写
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试报告",description="这是我的第一个测试报告")
    runner.run(testsuit)

#如果看不懂上面的代码,可以去参看unittest的单元测试
#fp = open("a.html","wb") w:只写,r:只读,a:追加
# fp.write("test")覆盖写入
#fp.close() 每次做完其他的操作,一定要记得关闭
#fp.read() 读出文件中的内容
#for x in fp.readline():  每次只读一行,当文件中的内容多时,可以用它
#   print(x)

2、写完代码,运行要注意,测试报告一定要用工具中的run

Selenium自动化测试----Lib\site-packages生成测试报告

3、打开生成的aa.html文件

Selenium自动化测试----Lib\site-packages生成测试报告

 

 


 

相关文章:

  • 2021-08-08
  • 2021-12-27
  • 2021-11-30
  • 2021-11-30
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2021-11-30
  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案