接口测试入门
2018-07-29 本文已影响339人
测试老杨
扫码关注本人公众号

什么是接口
供外部(界面客户端或第三方系统)访问的后台程序,该后台程序能够对外部发送过来的请求进行处理,并返回处理的结果。
接口测试的依据
接口文档(接口的功能说明书)
接口测试的工具
Post Man
Soup UI
Jmeter
HttpClient + fastjson + TestNG
JSON数据格式
比如:
{"empNo":"S201","ename":"张三","age":23,"sal":8000.0,"dept":{"deptID":10,"dname":"销售","loc":"上海"}}
{"emps":[{"empNo":"S201","ename":"张三","age":23,"sal":8000.0,"dept":{"deptID":10,"dname":"销售","loc":"上海"}},{"empNo":"A101","ename":"李四","age":27,"sal":12000.0,"dept":{"deptID":10,"dname":"工程","loc":"苏州"}}]}
Post Man官方教程
https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests
视频管理接口测试的案例
查看上传视频的接口说明
http://dev.polyv.net/2014/videoproduct/v-api/v-api-upload/uploadfile/





使用Post Man工具发送上传视频的请求

检查上传的视频是否可以正常播放
http://mpv.videocc.net/705e4a6271/2/705e4a627167304c20497ed1f7c91672_1.mp4

查看按标签查找视频的接口说明





使用Post Man发送查找视频的请求
1、生成时间戳

2、生成sign
查取secretkey和userid

secretkey为:g6UuoJKst3
userid为:705e4a6271
明文如下:
ptime=1532848683000&tag=demog6UuoJKst3
加密结果:
http://tool.oschina.net/encrypt?type=2

加密结果为:
750c9d361cc3f068ef2bc4cddc0d2fefa09fe9fa
将加密结果转成大写字母:
https://www.iamwawa.cn/daxiaoxie.html

3、构造并发送查找视频的请求
请求地址如下:
http://api.polyv.net/v2/video/705e4a6271/search?ptime=1532848683000&tag=demo&sign=750C9D361CC3F068EF2BC4CDDC0D2FEFA09FE9FA

使用Post Man发送编辑单个视频的信息的请求



使用Post Man发送查询视频播放量统计数据的请求



使用Post Man发送删除视频的请求

使用Post Man对返回的结果进行验证
tests["Body matches string"] = responseBody.has("\"code\":400");

