python的自動化測試報告


#coding=utf-8
import HTMLTestRunner
import BeautifulReport
import unittest
class MyTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("所有之前運行")
@classmethod
def tearDownClass(cls):
print("所有之后運行")
def setUp(self):
print("之前運行")
def tearDown(self):
print("之后運行")
def test_calc1(self):
'''這是測試報告1'''
print("這是case1")
def test_calc2(self):
'''這是測試報告2'''
print("這是case2")
-------------------------------------------------------------------------------------------------------------------------------------------

# unittest.main()
# test_suite=unittest.TestSuite()
# test_suite.addTest(MyTest('test_calc2'))
# test_suite.addTest(unittest.makeSuite(MyTest))
# f=open('report.html','wb',)
# runner=HTMLTestRunner.HTMLTestRunner(stream=f,title='測試報告',description='濤濤測試報告')
# runner.run(test_suite)
# f.close()
HTMLTestRunner下載地址:
https://pan.baidu.com/s/1mPbGvplcw2o0qpxloyDe0g 密碼:ubo4    解壓后要放到lib目錄下  運行一定要 run ..形式運行

------------------------------------------------------------------------------------------------------------------------------

report=BeautifulReport.BeautifulReport(test_suite)
report.report(description='牛牛報告',filename='report3.html2')
print(report.failure_count)#失敗的次數
print(report.success_count)#成功的次數
BeautifulReport下載地址:鏈接:https://pan.baidu.com/s/1mPbGvplcw2o0qpxloyDe0g 密碼:ubo4    解壓后要放到site-packages目錄下
--------------------------------------------------------------------------------------------------------------------------------------------------
多個用例如何在一個文件運行呢 在selenium新建一個文件夾 case  下面新建兩個case  在selenium新建一個執行文件
import  unittest
import BeautifulReport as br
test_suite=unittest.TestSuite()
all_case=unittest.defaultTestLoader.discover('case','*.py')
[test_suite.addTests(case)for case in all_case]
report=br.BeautifulReport(test_suite)
report.report(description='濤濤測試用例',filename='new.html')
---------------------------------------------------------------------------------------------------------------------------------------

 











免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM