• unittesr框架2测试用例集及报告


    if __name__=='__main__':
    unittest.main(verbosity=2)

    suite=unittest.TestSuite() #定义一个测试测试套件

    #添加部分测试用例, 为什么会报错,
    #suite.addTest(Test_calculator("test_add"))
    #suite.addTest(Test_calculator("test_multiplay"))
    #suites=(Test_calculator('test_add'),Test_calculator('test_sbtrct'),Test_calculator('test_multiplay') ,Test_calculator('test_divide'))
    #suite.addTest(suites) 为什么这个会失败 我也理解不了
    添加用例,函数为什么要引号
    runner = unittest.TextTestRunner
    #runner.run(suite) 执行测试套件里面的测试用例

    #添加全部测试用例
    #suite=unittest.makeSuite(Test_calculator) 定义当前时间
    # currenttime=time.strftime('%y%m%d%H%M%S')
    # filename='./'+'report'+currenttime+'.html'
    # fp=open(filename,'wb')
    # runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试报告",description="测试描述") #自定义测试报告
     
    #简单的测试报告形式
    currenttime=time.strftime('%y%m%d%H%M%S')   定义当前时间
    file='./'+'report'+currenttime+'.html'
    fp=open(file,'w',encoding='utf-8')创建文件名称
    runner = unittest.TextTestRunner(stream=fp, descriptions='这是简单的测试报告!',verbosity=2)
    runner.run(suite)
    # with open('test_result.txt', 'w', encoding='utf-8') as file:
    # runner = unittest.TextTestRunner(stream=file, descriptions='这是简单的的测试报告!', verbosity=2)
    # runner.run(suite)

    ------------
    复杂点的html版测试报告,要下载
    HTMLTestRunner 模块
    添加用例后的操作:
    # currenttime=time.strftime('%y%m%d%H%M%S')
    # filename='./'+'report'+currenttime+'.html'
    # fp=open(filename,'wb')
    # runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title="测试报告",description="测试描述") #自定义测试报告
    # runner.run(suite)

    下载地址: http://tungwaiyip.info/software/HTMLTestRunner.html
    HTMLTestRunner.py的存放路径,是放在C:UsersAdministratorAppDataLocalProgramsPython37Lib
    HTMLTestRunner.py是基于python2*开发的,要想能够在python3上使用,需要修改该文件。
    修改汇总: 
    第94行,将import StringIO修改成import io
    第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()
    第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:
    第766行,将uo = o.decode('latin-1')修改成uo = e
    第772行,将ue = e.decode('latin-1')修改成ue = e
    第631行,将print >> sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, ' Time Elapsed: %s' % (self.stopTime-self.startTime))




     
  • 相关阅读:
    Hasura GraphQL schema 生成是如何工作的
    一张方便的graphql schema 语言手册
    使用lua graphql 模块让openresty 支持graphql api
    PostgREST docker-compose 试用
    subzero 基于postgrest && openresty && rabbitmq 的快速rest/graphql 开发平台
    使用blessed 开发丰富的cli 应用
    一个方便查看数据库转换rest/graphql api 的开源软件的github 项目
    treeql 基于rest 标准的接口开发协议
    graphql-modules 企业级别的graphql server 工具
    hangfire docker-compose 运行
  • 原文地址:https://www.cnblogs.com/huaihe/p/12764903.html
Copyright © 2020-2023  润新知