[Python] 通过HTMLTestRunner自动生成测试报告
作者:互联网
# -*- encoding:utf-8 -*-
import unittest2
from HTMLTestRunner import HTMLTestRunner
from selenium import webdriver
# create TestClass and inherit from unittest2.TestCase
class Baidu(unittest2.TestCase):
def test_baidu(self):
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.quit()
# Create test unit tester,add testcase by addTest method with format.
tester = unittest2.TestSuite()
tester.addTest(Baidu("test_baidu")) # format:addTest(TestClassName("methodName"))
with open('./result3.html', "w") as f:
# create HTMLTestRunner object and set params: stram= opened file, title and desc.
runner = HTMLTestRunner.HTMLTestRunner(stream=f, title="百度测试", description="ceshi")
# run test.
runner.run(tester)
标签:测试报告,tester,Python,HTMLTestRunner,test,import,addTest,unittest2 来源: https://www.cnblogs.com/zzmm0514/p/14367282.html