单元测试加入到自动化测试报告里面

login.py块:

#-*- coding:utf-8 -*-
from selenium import webdriver
import time

#打开浏览器
driver = webdriver.Firefox()
#最大化窗口
driver.maximize_window()
#打开京东
driver.get("http://www.baidu.com")
#休眠一秒
time.sleep(10)

#关闭浏览器
driver.close()

==================================
testcase.py块:
# -*-coding:utf-8 -*-
import unittest
#unittest.TestCase 相当于java里的继承
#声明类  单元测试
class TestUnittest(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print "setUpClass"
        pass
    def setUp(self):
        print "setUp"
        #pass为占位符
        pass
    def tearDown(self):
        print "tearDown"
        pass

    @classmethod
    def tearDownClass(self):
        print "tearDownClass"
        pass

    def test_us_em_pw_em(self):
        print "test_us_em_pw_em"
        pass
    def test_us_em_pw_em1(self):
        print "test_us_em_pw_em1"
        pass

if __name__ == '__main__':
        unittest.main()


=================================
suit.py块:
# -*- coding:utf-8 -*-
import unittest
from login import testcase
import HTMLTestRunner
suit = unittest.TestSuite()

#将单元测试加入到测试条件里面
suit.addTest(unittest.makeSuite(testcase.CeshiUnittest))

filename = 'D:/jd.html'

files = file(filename,'wb')
#加入自动化测试报告
runner = HTMLTestRunner.HTMLTestRunner(stream=files,title=u'京东',description=u'测试用例')
runner.run(suit)


你可能感兴趣的:(单元测试加入到自动化测试报告里面)