unittest使用BeautifulReport庫生成測試報告


首先我們下載BeautifulReport庫
紅色字體為重點部分
需要把他的包中的BeautifulReport.py放入Python下的Lib中不然會報錯

 

 在然后把包中的template模板也放入Python下的Lib中,因為源碼中默認模板路徑在是py下的lib中

 

 

 


import unittest
from BeautifulReport import BeautifulReport class TestStringMethods(unittest.TestCase): def test_upper(self): '''第一個測試用例''' self.assertEqual('foo'.upper(), 'FOO') def test_isupper(self): '''第二個測試用例''' self.assertTrue('FOO'.isupper()) self.assertFalse('Foo'.isupper()) def test_split(self): '''第三個測試用例''' s = 'hello world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): s.split(2) if __name__ == '__main__': test_suite=unittest.TestSuite() loader=unittest.TestLoader() test_suite.addTests(loader.loadTestsFromTestCase(TestStringMethods)) # unittest.TextTestRunner(verbosity=2).run(test_suite) run = BeautifulReport(test_suite) # 實例化BeautifulReport模塊 run.report(filename='測試報告', description='綜合招標單表標段全流程')
使用BeautifulReport生成測試報告的話不能直接執行測試用例不然會拋錯
可以查看report函數源碼 知道怎么設置測試用例頭,路徑,模板樣式

 

 然后直接執行就行了

 

 


免責聲明!

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



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