1. A simple test report
2.HTMLTestRunner test report
Because HTMLTestRunner is based python2 developed python3 if you want to use, you need to change it:
3. Readability Test Report (optimization)
1) when the test because we do not know the report is measured which of the use cases, it may be the class or method of adding the annotation, the annotation Python is divided into two, one is Comment A is readable the doc string, the comment with triple quotes "" "" "" or '' '' ''
Time 2) use case execution times, each time to modify the name of the report, if the report is not modified, will be covered before, so the best way is to add the current time ~!
import time
#..........
if __name__=='__main__':
suit=unittest.TestSuite()
suit.addTest (Baidu ( 'test_baidu'))
now=time.strftime('%Y-%m-%d %H_%M_%S)
filename='./' + now + 'result.html'
fp=open(filename,'wb')
runner== HTMLTestRunner(stream=fp,
title = 'interface to automatic test report',
description = 'implementation use cases:'
)
runner.run(suit)
fp.close()
4. Project Integration Test Report
Want to perform all the files in the directory testcase, one written suit.add () was too much trouble:
import unittest,time
from HTMLTestRunner import HTMLTestRunner
# Designated as a test case under the current folder testcase directory
= test_dir '. / test_case'
# designated to perform all matter contained in the test directory _ *. py file
discover=unittest.defaultTetLoader.discover(test_dir,pattern='test_*.py')
if __name__=='__main__':
.............
Reproduced in: https: //www.jianshu.com/p/cb408bc67524