from test_login import Test_login import unittest from HTMLTestRunner import HTMLTestRunner if __name__=="__main__": suit = unittest.TestSuite() suit.addTest(Test_login("test_success_login")) suit.addTest(Test_login("test_failed_login")) suit.addTest(Test_login("test_null_login")) with(open('./login_result.html', 'wb')) as fp: runner = HTMLTestRunner(stream=fp,title="163邮箱登录测试报告", description="运行环境:win10, Chrome浏览器") runner.run(suit)
给 Test_login模块加上doc string注释,使得报告更易读。
测试报告命名加上时间戳
from test_login import Test_login import unittest from HTMLTestRunner import HTMLTestRunner import time if __name__=="__main__": suit = unittest.TestSuite() suit.addTest(Test_login("test_failed_login")) suit.addTest(Test_login("test_null_login")) suit.addTest(Test_login("test_success_login")) now_time = time.strftime("%Y-%m-%d %H_%M_%S") with open(now_time+' login_function.html', 'wb') as fp: runner = HTMLTestRunner(stream=fp,title="163邮箱登录测试报告", description="运行环境:win10, Chrome浏览器") runner.run(suit) fp.close()