• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Broke_薪雪
博客园    首页    新随笔    联系   管理    订阅  订阅

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)

 

posted @ 2018-12-11 21:08  Broke、薪雪  阅读(910)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3