说明

用法

不使用模糊测试

使用模糊测试

报告

其他

需要登录

def get_session():
    req = requests.session()
    url = ""
    data = {}
    req.post(url, data, verify=False)
    return req


class ParametrizedTestCase(unittest.TestCase):


    def __init__(self, methodName='runTest', param=None):
        super(ParametrizedTestCase, self).__init__(methodName)

    @classmethod
    def setUpClass(cls):
        cls.rq = get_session() # 登录后的session
        pass

class ApiTest(ParametrizedTestCase):
    def test_api(self):
        ls = read_excel(Element.API_FILE)
        # self.req 就是得到了登录后的信息session 
        Config().config_req(ls,self.req)

    @classmethod
    def setUpClass(cls):
        super(ApiTest, cls).setUpClass()


pict 生成的异常场景

def __param_format(self, key):
       param_type = {
           str: lambda: str(uuid.uuid1()),
           list: lambda: [],
           dict: lambda: {}
       }
       return param_type[type(key)]()

检查点说明

def __check(self, hope, res):
    hope = json.loads(hope)
    fact = json.loads(res)
    for items in fact:
        if type(fact[items]) == list:
            for item in fact[items]:
                for k in hope:
                    if item.get(k, "") == hope[k]:
                        return "通过"
        if type(fact[items]) == dict:
            for k in hope:
                if fact[items].get(k, "") == hope[k]:
                    return "通过"
        for k in hope:
            if fact.get(k, "") == hope[k]:
                return "通过"
    return "失败"


↙↙↙阅读原文可查看相关链接,并与作者交流