码迷,mamicode.com
首页 > 其他好文 > 详细

unittest使用BeautifulReport库生成测试报告

时间:2020-01-13 14:27:10      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:string   lse   用例   ring   unittest   method   class   实例化   函数   

首先我们下载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函数源码 知道怎么设置测试用例头,路径,模板样式
技术图片

 

 然后直接执行就行了

技术图片

 

 

unittest使用BeautifulReport库生成测试报告

标签:string   lse   用例   ring   unittest   method   class   实例化   函数   

原文地址:https://www.cnblogs.com/test-hui/p/12187041.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!