Nicole2333

导航

inteface testing

 

扫盲: 接口测试原理   https://blog.csdn.net/HuDi_2017/article/details/90742864

postman界面

 postman 使用技巧  http://bbs.51testing.com/thread-1205044-1-1.html

                                postman 进行http接口测试

总结:学postman最好学一下js  Tests 功能的使用需要有一定的编程语言基础,目前支持的脚本语言即为 JavaScript Postman 还为我们提供了一些常用的代码模板,在 Tests 面板右边的 SNIPPETS 功能区中,所以对 JavaScript不大了解问题也不大

代码模板
Postman 在 SNIPPETS 功能区中为我们提供的代码模板已经能解决大部分情况了,以下先挑几个跟结果判断相关的进行讲解:

Status code : Code is 200

//根据返回的 Code 判断请求情况
tests["Status code is 200"] = responseCode.code === 200;

Response body: Contains string

//判断返回的内容中是否存在“关键字”。(tests 的 key 可修改,将不再强调)
tests["Body matches string"] = responseBody.has("这里可以改为你要判断的关键字内容");

//如上文提到的:
// 判断结果中是否存在 access_token 关键字
tests["has access_token"] = responseBody.has("access_token");

Response body: is equal to string

//判断返回内容是否跟预期完全相等。
tests["Body is correct"] = responseBody === "这里可以改为你的预期内容";

Response body: JSON value check

//上文提到,responseBody 为字符串类型,支持转为 Json 格式
var jsonData = JSON.parse(responseBody);
tests["Your test name"] = jsonData.value === 100;

Response time is less than 200ms

//判断请求时长是否小于200ms ,具体时长按情况自定义
tests["Response time is less than 200ms"] = responseTime < 200;

看这一篇就够了

posted on 2019-07-17 11:03  Nicole2333  阅读(137)  评论(0)    收藏  举报