1. 程式人生 > >將unitest整合和python傳送測試報告

將unitest整合和python傳送測試報告

廢話少說先上程式碼

# -*- coding:UTF-8 -*-
__autor__ = 'zhouli'
__date__ = '2018/11/12 21:29'

import unittest
import unittest_import, test_suite


def create_suite():
    print('開始測試')
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(unittest_import.UserTestCase))  # 加上測試用例中類的名稱即可
    suite.addTest(unittest.makeSuite(test_suite.UserTestCase))  #
加上測試用例中類的名稱即可 return suite if __name__ == "__main__": suite = create_suite() file_prefix = time.strftime("%Y-%m-%d", time.localtime()) print(file_prefix) with open("./" + file_prefix + "_result.html", "wb") as f: runner = HTMLTestRunner.HTMLTestRunner(stream=f, title=u"
zl測試", description=u"執行情況") runner.run(suite)

值得注意的是其他模組的測試是通過addTest來完成的