亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Postman接口測試_添加斷言

標簽:
測試


1.设置环境变量
 postman.setEnvironmentVariable("key", "value"); 
 例子: postman.setEnvironmentVariable("url", "http://192.168.36.47/v2/api"); 
使用环境变量的格式:{{url}}

1.1清除环境变量
postman.clearEnvironmentVariable("variable_key");
例子:postman.clearEnvironmentVariable("url");


2.设置一个全局变量
postman.setGlobalVariable("key", "value"); 
例子:postman.setGlobalVariable("username", "[email protected]");
使用全局变量格式:{{variableName}}

2.1清除一个全局变量
postman.clearGlobalVariable("key", "value"); 
例子:postman.clearGlobalVariable("username", "[email protected]"); 


3.检查响应体包含一个字符串
 tests["Body matches string"] = responseBody.has("string_you_want_to_search"); 
 例子:响应体包含以下字段 "path": "field is read-only",
tests["Body matches string"] = responseBody.has("field is read-only"); 
tests["Body matches string"] = responseBody.has("path"); 

4.转换XML身体JSON对象
 var jsonObject = xml2Json(responseBody);


5.检查响应体等于一个字符串
 tests["Body is correct"] = responseBody === "response_body_string"; 
例子:响应体包含以下字段 "path": "field is read-only",
tests["Body is correct"] = responseBody === "response_body_string"; 


6.检查一个JSON值
 var data = JSON.parse(responseBody); 
 tests["Your test name"] = data.value === 100; 


7.Content-Type的存在(不区分大小写检查)
 tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists. 



8.Content-Type的存在(区分大小写)
 tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type"); 



9.响应时间小于200ms的
 tests["Response time is less than 200ms"] = responseTime < 200; 



10.状态代码是200
 tests["Status code is 200"] = responseCode.code === 200; 
 例子:状态码是404
 tests["Status code is 404"] = responseCode.code === 404;



11.代号包含一个字符串
 tests["Status code name has string"] = responseCode.name.has("Created"); 
例子:Status:201 CREATED
 tests["Status code is 201"] = responseCode.code === 201; 
 tests["Status code name has string"] = responseCode.name.has("Created"); 


12.成功的POST请求的状态代码
 tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202; 

作者:倾听起风

原文链接:https://www.cnblogs.com/zocymo/p/9990252.html

點擊查看更多內容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消