├── Postman ├── README.md ├── postman心得(一).md ├── postman心得(三).md └── postman心得(二).md └── README.md /Postman/README.md: -------------------------------------------------------------------------------- 1 | # Postman简介 2 | postman是一款功能强大的网页调试与发送网页HTTP请求的工具。postman能够发送任何类型的HTTP请求(GET, HEAD, POST,PUT..),附带任何数量的参数和HTTP headers。支持不同的认证机制(basic, digest,OAuth),接收到的响应语法高亮(HTML,JSON或XML)。 3 | 4 | postman既可以以chrome浏览器插件的形式存在,也可以是独立的应用程序存在。可以到[https://www.getpostman.com/](https://www.getpostman.com/)下载。 -------------------------------------------------------------------------------- /Postman/postman心得(一).md: -------------------------------------------------------------------------------- 1 | # postman使用心得(一):postman基础理论 # 2 | ## 在使用postman中 form-data、x-www-form-urlencoded、raw、binary的区别 ## 3 | ### from-data ### 4 | 为http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开。既可以上传键值对,也可以上传文件。当上传的字段是文件时,会有Content-Type来表名文件类型;content-disposition,用来说明字段的一些信息 5 | ![from-data](http://upload-images.jianshu.io/upload_images/9673971-d579903ccad749a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 6 | >multipart表示的意思是单个消息头包含多个消息体的解决方案,multipart媒体类型对发送非文本的各媒体类型是有用的。一般多用于文件上传。 7 | 8 | ### x-www-form-urlencoded ### 9 | 为application/x-www-from-urlencoded,窗体数据被编码为名称/值对,这是标准且默认的编码格式。当action为get时候,客户端把form数据转换成一个字串append到url后面,用?分割。当action为post时候,浏览器把form数据封装到http body中,然后发送到server 10 | ![x-www-form-urlencoded](http://upload-images.jianshu.io/upload_images/9673971-5436056c3cb4863b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 11 | 12 | ### raw ### 13 | 可以上传任意格式的文本,可以上传text、json、xml、html等 14 | ![raw](http://upload-images.jianshu.io/upload_images/9673971-a66b16b1ecf159e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 15 | 16 | ### binary ### 17 | 相当于Content-Type:application/octet-stream,从字面意思得知,只可以上传二进制数据,通常用来上传文件,由于没有键值,所以,一次只能上传一个文件。 18 | 19 | ## 关于HTTP动词 ## 20 | **其实http请求完全不止于常见的get,post**,参考[RESTful架构](http://www.ruanyifeng.com/blog/2011/09/restful.html) 21 | 22 | 客户端通过HTTP动词,对服务器端资源进行操作,实现"表现层状态转化" 23 | - GET(查询):从服务器取出资源(一项或多项) 24 | - POST(增加):在服务器新建一个资源 25 | - PUT(更新):在服务器更新资源(客户端提供完整资源数据) 26 | - PATCH(更新):在服务器更新资源(客户端提供需要修改的资源数据) 27 | - DELETE(删除):从服务器删除资源 28 | -------------------------------------------------------------------------------- /Postman/postman心得(三).md: -------------------------------------------------------------------------------- 1 | # postman使用心得(三):轻便快捷的接口自动化持续集成实现方式 # 2 | ## 环境配置 ## 3 | 1. 安装postman([https://www.getpostman.com/](https://www.getpostman.com/)) 4 | 2. 下载安装nodejs ([https://nodejs.org/en/download/](https://nodejs.org/en/download/)) 5 | 3. 在控制台输入node,如果显示“>”,说明安装成功![node验证](https://upload-images.jianshu.io/upload_images/9673971-c09a356224ba6f13.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 6 | 7 | 8 | 4. 在控制台输入```npm install -g newman ```下载newman![下载newman.png](https://upload-images.jianshu.io/upload_images/9673971-75ccb70805f85187.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 9 | 10 | 5. 验证newman版本,在控制台输入newman --version![查看newman的版本](https://upload-images.jianshu.io/upload_images/9673971-f9fbf4b9bdece790.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 11 | 12 | 13 | ##postman的用例集的操作 14 | 1. 在postman的collection添加一个测试集合文件夹 15 | ![添加用例集合](https://upload-images.jianshu.io/upload_images/9673971-1575025938dda9f3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 16 | 17 | 2. 导出用例集的,存为json格式 18 | ![用例集合导出](https://upload-images.jianshu.io/upload_images/9673971-15e85e60e1afafb7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 19 | 20 | 3. 使用newman命令```newman run 文件地址```,运行导出的测试用例集! ![newman运行](https://upload-images.jianshu.io/upload_images/9673971-eb5822445d37f16a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 21 | 22 | 4. 生成html格式的报告```newman run postman导出的用例集合.json -r html```![输出html格式](https://upload-images.jianshu.io/upload_images/9673971-4745e2f440646098.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 23 | 24 | 25 | 5. newman常用命令集([https://github.com/postmanlabs/newman#configuring-reporters](https://github.com/postmanlabs/newman#configuring-reporters)) 26 | 27 | 28 | ## jenkins的持续集成 29 | 1. jenkins下载([https://jenkins.io/](https://jenkins.io/)) 30 | >安装之前需要说明:需要先安装jdk,这里我本机已经安装,此处不再赘述。安装jdk之后可以查看jdk是否安装好,jdk -version 31 | 2. 安装成功后,访问http://localhost:8080,默认端口号是8080 32 | 3. 在jenkins主页,新增一个项目![jenkins主页](https://upload-images.jianshu.io/upload_images/9673971-7e59b42c9257c940.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 33 | 34 | 4. 在项目主页中打开配置![项目配置](https://upload-images.jianshu.io/upload_images/9673971-0166b302d7ade65f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 35 | 36 | 5. 在配置的构建中输入命令运行路径```newman run C:\Users\windz\Desktop\test.ctb.postman_collection.json -r html```![构建配置](https://upload-images.jianshu.io/upload_images/9673971-2cc64b005ad17974.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 37 | 38 | 开始执行吧! 39 | -------------------------------------------------------------------------------- /Postman/postman心得(二).md: -------------------------------------------------------------------------------- 1 | # postman使用心得(二):postman接口测试断言 # 2 | 3 | ## 在使用postman做接口测试的时候,可以在tests中对该接口进行断言设置 ## 4 | ![json字符串解析断言](http://p4uuxwp7i.bkt.clouddn.com/%E6%8E%A5%E5%8F%A3%E8%BF%94%E5%9B%9E.png) 5 | 6 | 上面的图为使用postman断言方法之一,使json解析key的值进行校验 7 | ``` 8 | tests["Your test name"] = jsonData.value === 100; 9 | ``` 10 | **其中 Your test name 为断言名,jsonData.value表示为对json进行解析,=== 100 表示为key的value值** 11 | ``` 12 | { 13 | "ok": true, 14 | "data": { 15 | "user": { 16 | "user_no": "888", 17 | "type": "1", 18 | "user_name": "W HE", 19 | "fullname": "W HE", 20 | "nickname": "", 21 | "login_name": "1258@qq.com", 22 | "headimg": "", 23 | "is_payed": true, 24 | "is_certified": false 25 | }, 26 | "redirect_url": "/team/search" 27 | } 28 | } 29 | ``` 30 | >jsonData["data"]["user"]["user_name"] === "W HE" 31 | 32 | ## 附: ## 33 | 34 | 35 | | 常用的postman断言 | 解释 | 对应脚本 | 36 | | -------------- | -------------- | ---------- | 37 | | Response body:Contains string | response包含字符串 | tests["Body matches string"] = responseBody.has("string_you_want_to_search"); | 38 | | Response body:Is equal to a string | response body等于指定字符串 | tests["Body is correct"] = responseBody === "response_body_string"; | 39 | | response body:JSON value check | json解析key的值进行校验 | tests["Your test name"] = jsonData.value === 100; | 40 | |status code:Code is 200 | 判断状态码 |tests["Status code is 200"] = responseCode.code === 200;| 41 | |status code:code name has string | 检查code name 是否包含内容 | tests["Status code name has string"] = responseCode.name.has("Created");| 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 关于接口测试 2 | ## 什么是接口测试 ## 3 | 接口测试是测试系统组件间接口的一种测试,接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点,测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑依赖关系等 4 | 5 | ## 为什么要做接口测试 ## 6 | 1. 如今的系统复杂度不断上升,传统的测试方法成本急剧增加且测试效率大幅下降,接口测试可以提供这种情况下的解决方案 7 | 8 | 2. 接口测试相对容易实现自动化持续集成,且相对UI自动化也比较稳定,可以减少人工回归测试人力成本与时间,缩短测试周期,支持后端快速发版需求。接口持续集成是为什么能低成本高收益的根源 9 | 10 | 3. 现在很多系统前后端架构是分离的,从安全层面来说: 11 | - 只依赖前端进行限制已经完全不能满足系统的安全要求(绕过前面实在太容易), 需要后端同样进行控制,在这种情况下就需要从接口层面进行验证 12 | - 前后端传输、日志打印等信息是否加密传输也是需要验证的,特别是涉及到用户的隐私信息,如身份证,银行卡等 13 | 14 | ## 目录引导 ## 15 | 16 | ### [postman使用随笔记录 ](https://github.com/StrawberryFlavor/interface-testing/tree/master/Postman) 17 | - [**postman使用心得(一):postman基础理论**](https://github.com/StrawberryFlavor/interface-testing/blob/master/Postman/postman%E5%BF%83%E5%BE%97%EF%BC%88%E4%B8%80%EF%BC%89.md) 18 | 19 | 20 | 21 | - [**postman使用心得(二):postman接口测试断言**](https://github.com/StrawberryFlavor/interface-testing/blob/master/Postman/postman%E5%BF%83%E5%BE%97%EF%BC%88%E4%BA%8C%EF%BC%89.md) 22 | 23 | 24 | 25 | - [**postman使用心得(三):轻便快捷的接口自动化持续集成实现方式**](https://github.com/StrawberryFlavor/interface-testing/blob/master/Postman/postman%E5%BF%83%E5%BE%97%EF%BC%88%E4%B8%89%EF%BC%89.md) --------------------------------------------------------------------------------