Python BeautifulReport可視化報告代碼實例
操作步驟
1.下載BeautifulReport文件,本例文件下載地址 最新文件下載地址
2.復制文件BeautifulReport,至python安裝Libsite-packages位置下
3.
3.導入:from BeautifulReport import BeautifulReport import unittest
4.testXXX測試用例函數下可視化報告用例描述:’’’描述,第一個測試用例’’’
5.mian下執行:
1.實例化:ts = unittest.TestSuite()
2.按類加載全部testxxx測試用例:ts.addTest(unittest.makeSuite(類名))按函數加載testxxx測試用例:ts.addTest(類名(‘函數名’))
3.加載執行用例生成報告:result = BeautifulReport(ts)
4.定義報告屬性:result.report(description=’XXX報告XX描述’, filename= ’xxx.html’, log_path=’C:UsersEDZeclipse-workspacepythonTestReport’)
舉例說明
#!/usr/bin/python3# encoding:utf-8’’’Created on 2019年9月30日@author: EDZ’’’import unittestfrom BeautifulReport import BeautifulReportimport osimport timeclass HtmlReport(unittest.TestCase): def test_1(self): ’’’描述,第一個測試用例’’’ print(’test_1錯誤’) self.assertEqual(1, 2) def test_2(self): ’’’描述,第二個測試用例’’’ print(’test_2正確’) self.assertEqual(1, 1) def test_3(self): ’’’描述,第三個測試用例’’’ print(’test_3錯誤’) self.assertEqual(2, 3)if __name__==’__main__’: now = time.strftime('%Y-%m-%d %H%M%S', time.localtime(time.time())) localpath = os.getcwd() print(’本文件目錄位置:’+localpath) filepath = os.path.join(localpath,’Report’) print(’報告存放路徑 :’+filepath) ts = unittest.TestSuite()#實例化 #按類加載全部testxxx測試用例 ts.addTest(unittest.makeSuite(HtmlReport)) #按函數加載testxxx測試用例 #ts.addTest(HtmlReport(’test_1’)) filename = now +’.html’ #加載執行用例生成報告 result = BeautifulReport(ts) #定義報告屬性 result.report(description=’XXX報告XX描述’, filename= filename, log_path=filepath)
控制臺運行結果
本文件目錄位置:C:UsersEDZeclipse-workspacepythonTest報告存放路徑 :C:UsersEDZeclipse-workspacepythonTestReportF.F測試已全部完成,可前往C:UsersEDZeclipse-workspacepythonTestReport查詢測試報告
可視化報告
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. php測試程序運行速度和頁面執行速度的代碼2. ASP中常用的22個FSO文件操作函數整理3. 三個不常見的 HTML5 實用新特性簡介4. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報錯問題分析5. ASP調用WebService轉化成JSON數據,附json.min.asp6. SharePoint Server 2019新特性介紹7. React+umi+typeScript創建項目的過程8. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁9. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析10. php網絡安全中命令執行漏洞的產生及本質探究
