<p style="margin-top:16px;color:rgb(34,34,34);font-family:'PingFang SC','Hiragino Sans GB','Microsoft YaHei','WenQuanYi Micro Hei','Helvetica Neue',Arial,sans-serif;background-color:rgb(255,255,255);">

<p style="margin-top:16px;color:rgb(34,255);">2. 方案<p style="margin-top:16px;color:rgb(34,255);">针对上面的API,在做接口测试时,需要的测试用例动辄会多达10+,这个时候采用数据驱动的方式将共性的
内容写入
配置文件或许会更合适。<p style="margin-top:16px;color:rgb(34,255);">这里考虑把API、参数、以及预期结果预行在格式化的CSV里保存,利用csv组件从CSV里读取URL、参数以及预期结果,Requests组件发起请求,将响应结果与预期结果进行比对,最后把比对结果写到结果CSV。<p style="margin-top:16px;color:rgb(34,255);">流程如下图<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">3. 实现<p style="margin-top:16px;color:rgb(34,255);">(1) 在上
代码之前,先安装好如下几个组件:<ul class="list-paddingleft-2" style="margin-bottom:0px;padding:20px 30px;list-style:square outside;color:rgb(34,255);"><li style="margin-top:0px;margin-left:0px;padding:0px;list-style:inherit;"><p style="margin-bottom:0px;">csv 读写CSV
文件<li style="margin-top:0px;margin-left:0px;padding:0px;list-style:inherit;"><p style="margin-bottom:0px;">json<li style="margin-top:0px;margin-left:0px;padding:0px;list-style:inherit;"><p style="margin-bottom:0px;">requests 发起请求,
获取响应结果<li style="margin-top:0px;margin-left:0px;padding:0px;list-style:inherit;"><p style="margin-bottom:0px;">unittest 测试用例调度<p style="margin-top:16px;color:rgb(34,255);">(2) data.csv(本示例选取部分用例)<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">(3) reader_CSV
函数代码示例<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">(4) request_URL
函数示例(包含GET请求和POST请求2个
方法)<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">(5) assert_Result
函数示例<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">(6) write_CSV
函数示例<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">(7) test_interface1
函数示例<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">8result_1523956055.csv(本示例中的测试结果请忽略)<p style="margin-top:16px;color:rgb(34,255);">

<p style="margin-top:16px;color:rgb(34,255);">4. 总结<p style="margin-top:16px;color:rgb(34,255);">留言给小编,小编会
回复给大家PDF的文档!