常用断言:
self.assertTrue()
self.assertEqual()
集成HtmlTestRunner生成测试报告:
testcase=unittest.TestSuite()
testcase.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
now = time.strftime(’%Y-%m-%d-%H-%M-%S’, time.localtime())
file=open(dir,‘wb’)
runner=HTMLTestRunner(stream=file,title=‘接口自动化测试报告’,description=‘描述信息’)
HTMLTestRunner
链接:https://pan.baidu.com/s/1mzTaI8WERE6euPfsysL8CQ
提取码:m5k7
#集合用例
import unittest
from Learn import test_http
import HTMLTestRunner
suite=unittest.TestSuite()
#通过loader方式来加载用例
loader=unittest.TestLoader()
suite.addTest(loader.loadTestsFromModule(test_http))
#执行
with open(r"D:\学习\Python工程\Learn\test_summer.html",)as file:
runner=HTMLTestRunner.HTMLTestRunner(stream=file,verbosity=2,title=“东方不败之鸭梨”,description=“练习HTML报告”)
runner.run(suite)
报错:
TypeError: write() argument must be str, not bytes
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200425173616437.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NlYW55YW5nXw==,size_16,color_FFFFFF,t_70)
参考这篇文章:
https://blog.csdn.net/kingyuan666/article/details/81214954
解决问题。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200425173917453.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NlYW55YW5nXw==,size_16,color_FFFFFF,t_70)
遗留问题:
#为什么HTML上不输出print?
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200425175449352.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NlYW55YW5nXw==,size_16,color_FFFFFF,t_70)
参考https://www.cnblogs.com/yrxns/p/11189394.html
竟然解决了。。。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200425175541622.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NlYW55YW5nXw==,size_16,color_FFFFFF,t_70)