[Postman & Integration Tests] Using Postman to Define Integration Tests
2023-09-14 09:00:46 时间
In Postman, you can create a collection of API requests. Those collection can be save into json file as well.
{ "info": { "_postman_id": "9c5a8003-1c58-4207-b843-85f2355aaf4a", "name": "udacity-c2-basic-server", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "exercise", "item": [ { "name": "/cars all", "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/cars/", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "cars", "" ] } }, "response": [] }, { "name": "/cars filter", "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/cars/?make=toyota", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "cars", "" ], "query": [ { "key": "make", "value": "toyota" } ] } }, "response": [] }, { "name": "/cars by id", "request": { "method": "GET", "header": [ { "key": "Content-Type", "name": "Content-Type", "value": "application/json", "type": "text" } ], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/cars/2", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "cars", "2" ] } }, "response": [] }, { "name": "/cars", "request": { "method": "POST", "header": [ { "key": "Content-Type", "name": "Content-Type", "value": "application/json", "type": "text" } ], "body": { "mode": "raw", "raw": "{ \"make\": \"ford\", \"type\": \"sedan\", \"model\": \"focus\", \"cost\": 12, \"id\": 9 }\n" }, "url": { "raw": "http://localhost:8082/cars", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "cars" ] } }, "response": [] } ] }, { "name": "http://localhost:8082/", "event": [ { "listen": "test", "script": { "id": "9b4015b7-faf5-4924-8661-7728ba94e410", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Body matches string\", function () {", " pm.expect(pm.response.text()).to.include(\"Welcome to the Cloud!\");", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "" ] } }, "response": [] }, { "name": "http://localhost:8082/persons/george", "event": [ { "listen": "test", "script": { "id": "277a3edb-b69d-4dcd-9b13-00d00faaca25", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Body matches string\", function () {", " pm.expect(pm.response.text()).to.include(`Welcome to the Cloud, george!`);", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/persons/:name", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "persons", ":name" ], "variable": [ { "key": "name", "value": "george" } ] } }, "response": [] }, { "name": "http://localhost:8082/persons/:name Copy", "event": [ { "listen": "test", "script": { "id": "7df7eec7-78b4-46f4-b2f5-2a7b994747e9", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Body matches string\", function () {", " var query = {};", " pm.request.url.query.all().forEach((p) => { query[p.key] = p.value});", " ", " pm.expect(pm.response.text()).to.include(`Welcome to the Cloud, ${query['name']}!`);", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/persons?name=george", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "persons" ], "query": [ { "key": "name", "value": "george" } ] } }, "response": [] }, { "name": "http://localhost:8082/persons/", "event": [ { "listen": "test", "script": { "id": "23433ca1-6ffc-4149-9e3c-97514d889ac5", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Body matches string\", function () {", " pm.expect(pm.response.text()).to.include(`Welcome to the Cloud, james!`);", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "name": "Content-Type", "value": "application/json", "type": "text" } ], "body": { "mode": "raw", "raw": "{\n \"name\": \"james\"\n}" }, "url": { "raw": "http://localhost:8082/persons", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "persons" ] } }, "response": [] }, { "name": "400 http://localhost:8082/persons/:name", "event": [ { "listen": "test", "script": { "id": "444e71e3-ae8c-469a-9da1-22aa3ee0792d", "exec": [ "pm.test(\"Status code is 400\", function () {", " pm.response.to.have.status(400);", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "http://localhost:8082/persons/", "protocol": "http", "host": [ "localhost" ], "port": "8082", "path": [ "persons", "" ] } }, "response": [] } ], "event": [ { "listen": "prerequest", "script": { "id": "6f442aeb-7c6b-401b-a76d-03a2c7b2cca9", "type": "text/javascript", "exec": [ "" ] } }, { "listen": "test", "script": { "id": "fae73fa3-4d3b-4528-a1af-a150ef18a902", "type": "text/javascript", "exec": [ "" ] } } ], "variable": [ { "id": "0db39ab1-774e-4108-8078-7a4d7df27657", "key": "endpoint", "value": "http://localhost:8082", "type": "string" } ] }
You can run the test against each request:
Also you can run the test against all the requests:
相关文章
- Spring学习笔记(三十)——SpringBoot对象拷贝总结&Mapstruct
- 也许有用(也谈VC中ModifyStyle&ModifyStyleEx无法改变控件的Style)[通俗易懂]
- Java Web(十一)Ajax&Axios&JSON
- Postman工具_postman安装使用教程
- Postman安装教程_postman需要联网吗
- 【文本检测与识别白皮书-3.2】第二节:基于CTC的无需分割的场景文本识别方法&基于注意力机制的无需分割的场景文本识别方法
- Assumptions & Constraints
- ChatGpt折腾&接入教程&在线体验
- MCE | 单胺能 & 非单胺能对抑郁症的作用
- 清华&商汤提出了神经SDF!从多个照明条件下单视图纯阴影或RGB图像重建!论文/代码速递2022.11.29!
- JS模块化之CJS&AMD&CMD&ES6-前端面试知识点查漏补缺
- ECCV 2022 | 普通VR设备实现全身运动捕捉,ETH&Meta为虚拟人物形象添加了下半身
- Python 线程&进程与协程
- 【进阶指针二】数组传参&指针传参&函数指针&函数指针数组&回调函数
- 接口测试|postman模拟请求头&界面的响应信息
- 接口测试|HttpRunner获取响应数据&extract提取值到变量
- 函数式编程:Flutter&Dart中的组合
- Git 源码泄露 && GitHack使用
- 用javascript分类刷leetcode6.深度优先&广度优先(图文视频讲解)_2023-03-15
- 【字符串匹配算法:BF & KMP】
- 如何增加Oracle数据库的AMP值(amp值oracle)
- JQuery的html(data)方法与<script>脚本块的解决方法
- Android控件系列之相册Gallery&Adapter适配器入门&控件缩放动画入门