当前位置:网站首页>Assertion of postman interface test
Assertion of postman interface test
2022-06-26 01:41:00 【NitefullSand】
Excerpt from :https://www.jianshu.com/p/5e69f2a304f8
One 、Postman Assertion
A complete interface test , Include : request -> Get the response body -> Assertion , We already know the request and get response body , Here's how to use postman To assert that .

Tests
This ”Tests” That's where we need to deal with assertions ,postman It's very humanized to help us prepare all the functions used for assertion :

SNIPPETS
Illustrate with examples : First set up an assertion scenario , Take the assertion scenario as an example Postman How assertions are used .
1、 Judge HTTP Returns the status code as 200
2、 Determine whether the response body contains :"statusCode":200
3、 Parse the response body , And decide statusCode The value of is 200,message The value of is ”Success”
First step : stay SNIPPETS in , Pull down , There is one ”Status code:Code is 200”, This is for the second 1 I'm ready for , Judge HTTP Returns whether the status code is 200. Click on this , You can see it on the left , Assertion code is added automatically , See the picture below :

Status code
The analysis is as follows :
pm.test["Status code is 200"] Medium test It's a built-in object ( function ),test["Status code is 200"] It means to give this assertion a name called ”Status code is 200”, The name can be changed by oneself .
pm.response.to.have.status(200) Medium responseCode It's a built-in object ,responseCode One of the properties in the object is code, Refer to HTTP Status code code, Judge code Is it 200.
combined , This code means : The name is ”Status code is 200” In the assertion of , Judge responseCode Object's code Property value (HTTP Status code ) Is it 200.
The second step : Also in SNIPPETS in , Find one ”Response body:Contains string”, This is for the second 2 I'm ready for , Determine the fields in the response body . After clicking , On the left , Assertion code is added automatically , See the picture below :

Contains string1
We need to modify what we want to find in the response message :
pm.expect(pm.response.text()).to.include("string_you_want_to_search"); // Compare with the second 2 A scene : Determine whether the response body contains :"statusCode":200

Contains string2
The third step : We need to parse JSON Yes , therefore , stay SNIPPETS Find ”Response body:JSON value check” And click the , On the left , Assertion code is added automatically , See the picture below :

JSON value check1
We can see that , It's actually JS Code ,jsonData Variables are actually parsed JSON After the object , stay JS in , One JSON Object gets the value of its property , It's direct jsonData.value, therefore , Let's modify the code , To judge the second 3 A scene :
pm.expect(jsonData.value).to.eql(200); // Judge statusCode The value of is 200
pm.expect(jsonData.value).to.eql('Success'); // Judge message The value of is ”Success”

JSON value check2
We can see that there are Tests Assertion of 4 individual , Click on Send, Send a request , In the response area, you can see the following figure :PASS Indicates that the assertion passed ,FAIL Indicates that the assertion failed .

Assert the running result
author :keitwo
link :https://www.jianshu.com/p/5e69f2a304f8
边栏推荐
- 正则表达式
- Laravel basic course routing and MVC - controller
- Set set!! Review quickly -- MySQL addition, deletion, modification and query, internal, left and right connection review notes
- 判定积分给业务带来价值的两个指标
- Oracle数据库开启备份准备工作
- STM32 key development foundation
- 【Visual Studio Code】vscode快捷键大全
- Etcd database source code analysis -- inter cluster network layer server interface
- Reading notes on how to connect the network - hubs, routers and routers (III)
- 21. Hoff circle transformation
猜你喜欢

Installing MySQL databases in FreeBSD

【花雕体验】11 上手ESP32C3

在FreeBSD中安装MySQL数据库

GNN (graph neural network) introduction vernacular

CityJSON

Region of Halcon: generation of multiple regions (4)

21. Hoff circle transformation

Oracle database startup backup preparation

Etcd database source code analysis cluster communication initialization

Discrete Mathematics - 01 mathematical logic
随机推荐
Reading notes on how to connect the network - hubs, routers and routers (III)
2022年电气试验考试试题模拟考试平台操作
Embedded C first learning notes
大周建议自媒体博主前期做这4件事
How to search papers in a certain field
I2C protocol
图文大师印章简易制作
正则表达式
经纬度 多点 获取中心点 已解决
Procédure de désinstallation complète de la base de données Oracle (pas de capture d'écran)
JSON instance (I)
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
"Hot post" Statistics
Oracle database complete uninstallation steps (no screenshot)
100ask seven day IOT training camp learning notes - bare metal program framework design
24. histogram calculation
**MySQL例题一(根据不同问题,多条件查询)**
手机卡开户的流程是什么?网上开户是否安全么?
弹性蛋白酶的用途和化学性质
Focal loss