unittest单元测试框架之测试结果输出到外部文件(四)
1.test_suit执行测试用例及输出结果前 添加如下代码(打开会新建d:/result.txt文件):
with open("d:\\result.txt","a") as f:
import unittest from UnittestDemo.test_mathfunc import TestMathFunc if __name__ == "__main__": suite = unittest.TestSuite() # 执行加法、减法、除法 tests =[TestMathFunc("test_add"),TestMathFunc("test_divide"),TestMathFunc("test_minus")] suite.addTests(tests) with open("d:\\result.txt","a") as f: #verbosity = 2 查看完成的执行情况 runner = unittest.TextTestRunner(stream=f, verbosity=2) runner.run(suite)