[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)
上一篇:linux的gpasswd的选项例子


下一篇:Jmeter察看结果树之CSSJQuery_Tester使用