当前位置:网站首页>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
边栏推荐
- Shengxin weekly issue 34
- 2022 documenter general basic (documenter) exam simulation 100 questions and online simulation exam
- --都市修炼手册之SQL-- 第一章 基础复习
- Tools - API document generation tool
- Flex & bison start
- MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
- Postman接口测试之断言
- I2C protocol
- 20. Hough line transformation
- 元素定位的八大法则
猜你喜欢

23. histogram equalization
![[flower carving experience] 11 start esp32c3](/img/ff/d7c266893ef4ef70c6536085927e0e.jpg)
[flower carving experience] 11 start esp32c3

Installing MySQL databases in FreeBSD

--SQL of urban cultivation manual -- Chapter 1 basic review

Discrete Mathematics - 01 mathematical logic

从在浏览器的输入框输入一个网址,到看到网页的内容,这个过程中发生了什么?

15 `bs object Node name Node name String` get nested node content

25. histogram comparison

Technical foreword - metauniverse

Obtain WiFi password through computer (only connected WiFi)
随机推荐
OTA trigger
JSON实例(一)
100ask seven day IOT training camp learning notes - bare metal program framework design
Basic concepts of machine learning
Rollback Protection
论文阅读 Exploring Temporal Information for Dynamic Network Embedding
UN make (6) makefile的条件执行
【Visual Studio Code】vscode快捷键大全
**MySQL example 1 (query by multiple conditions according to different problems)**
APP测试(一)
Test questions and answers for the 2022 baby sitter (Level 5) examination
Black box test - decision table method of test cases
Abnova丨ACTN4 DNA 探针解决方案
"Hot post" Statistics
halcon之区域:多种区域(Region)生成(4)
Abnova丨CSV 单克隆抗体解决方案
24. histogram calculation
JSON basic syntax
26. histogram back projection
MySQL例题一 综合案例(多条件组合查询)