• 接口测试困难


    一、断言

    1.数据结构判断(将值的内容忽略)通过字典键值、列表长度

    2.判断预期与响应完全一致(列表按顺序或没有列表的情况)

    def assert_equal(self,expect_value,response,*args):
        # 响应结果中的列表顺序必须与预期结果的顺序完全一致,否则会断言失败
        global remove_args
        remove_args = [arg for arg in args]
        if isinstance(expect_value,(list,tuple)):
            assert isinstance(response,(list,tuple)),"%s 不是列表,请核查!" %response
            assert len(expect_value) == len(response)
            if len(expect_value) != 0:
                for exp,res in zip(expect_value,response):
                    self.assert_equal(exp,res,*args)
        elif isinstance(expect_value,dict):
            assert isinstance(response,dict),"%s 不是字典,请核查!" %response
            for k in expect_value.keys():
                assert k in response.keys()
                if k in remove_args :
                    continue
                else:
                    # assert k in response.keys()
                    self.assert_equal(expect_value[k],response[k],*args)
        elif isinstance(expect_value,(int,bool,str)):
            assert expect_value == response,"%s 不等于 %s" %(expect_value,response)
    

      

    3.判断响应数据是否包含关键字

    def assert_contain(self,expect_value,response,*args):
            ''' bool型无法转换并判断是否包含'''
            global remove_args
            remove_args = [arg for arg in args]  # 取消断言的key
            if isinstance(expect_value,(list,tuple)):
                for i in expect_value :
                    self.assert_contain(i,response,*args)
            elif isinstance(expect_value,dict) :
                for k,v in expect_value.items():
                    if k in remove_args :
                        continue
                    else:
                        self.assert_contain(v,response,*args)
            elif isinstance(expect_value,(int,bool)) :
                self.assert_contain(str(expect_value),response,*args)
            elif isinstance(expect_value,str) :
                print(expect_value)
                assert expect_value in json.dumps(response,ensure_ascii=False),"%s 不在响应结果中,请核查!" %expect_value
    

    4.判断结果不包含关键字

    def assert_not_contain(self,expect,reponse):
            assert expect not in json.dumps(reponse,ensure_ascii=False),"%s 在响应结果中,请核查!" %expect
    

    5.下载文件与预期结果对比

    二、遇到的困难

    1.接口文档在用与废弃未及时更新

    2.代码复制,未修改注释,导致接口说明不清晰

  • 相关阅读:
    软工实践2019——第二次作业评分
    预培训-个人项
    预培训-阅读-快速阅读并提问
    nodejs异常处理过程/获取nodejs异常类型/写一个eggjs异常处理中间件
    写一个eggjs权限验证中间件
    eggjs的参数校验模块egg-validate的使用和进一步定制化升级
    个人作业——软件工程实践总结作业
    python性能分析(一)——使用timeit给你的程序打个表吧
    软工实践(五)——获小黄衫有感
    团队作业第二次—项目选题(追光的人)
  • 原文地址:https://www.cnblogs.com/cliu/p/12159943.html
Copyright © 2020-2023  润新知