将接口3进行结构的初步优化
#对多个接口组成的联调测试的脚本进行结构优化importrequests#定义一个接口联调的测试类classWorkflow_Forgetpassword_Test_v2():defuserinterface_test(self,url,userinfo,expected_result,interfacenam:response=requests.post(url,data=userinfo).textprint(responsr=responsfind(expected_result)ifr>0:print(interfacename,'测试通过')else:print(interfacename,'测试失败')if__name__=='__main__':workflowobj2=Workflow_Forgetpassword_Test_v2()########################注册接口测试数据及调用###################################url='http://localhost:8080/jwshoplogin/user/register.do'#正确的用户注册数据userinfo={'username':'刘婷3','password':'123456','email':'liuting3@qq.com','phone':'13311111111','question':'喜欢吃的水果','answer':'香蕉'}expected_result='注册成功'interfacename='用户注册接口'workflowobjuserinterface_test(url,userinfo,expected_result,interfacenam########################登录接口测试数据及调用####################################url='http://localhost:8080/jwshoplogin/user/logido'#正确的用户登录数据userinfo={'username':'刘婷3','password':'123456'}expected_result='登录成功'interfacename='用户登录接口'workflowobjuserinterface_test(url,userinfo,expected_result,interfacenam########################忘记密码接口测试数据及调用##################################url='http://localhost:8080/jwshoplogin/user/forget_get_questiodo'#忘记密码对应的用户userinfo={'username':'刘婷3'}expected_result='喜欢吃的水果'interfacename='忘记密码接口'workflowobjuserinterface_test(url,userinfo,expected_result,interfacenam
脚本结构化的价值:最大程度上提高了测试脚本的复用降低了测试脚本的维护成本只需要不断的追加或替换相关的测试数据即可方便后续接口测试工作的扩展以及测试执行如何进行接口测试脚本结构优化:首先优化测试脚本类的设计对应的接口测试方法需要传入参数接口访问地址接口参数---字典数据接口预期返回结果接口名称在进行类的实例化的时候,再依据接口测试说明传入相关的参数值。适用范围适合于接口测试不需要返回值,也不需要特殊参数时接口请求方式是一致的----比如post。
优化任务:
脚本实现:
脚本结构化的价值:最大程度上提高了测试脚本的复用如何进行接口测试脚本结构优化:适用范围
文章为作者独立观点,不代表股票交易接口观点