当前位置:网站首页>Postman assertion
Postman assertion
2022-06-24 20:47:00 【m0_ sixty-two million four hundred and ninety-six thousand nine】
A complete interface test , Include : request -> Get the response body -> Assertion You can see postman How to add assertions
This ” Tests” That's where we need to deal with assertions ,postman Help us prepare all the functions used for assertions
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”
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
This means that The name is ” Status code is 200” In the assertion of , Judge responseCode Object's code Property value (HTTP Status code ) Is it 200
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 , Generate the following code
We need to modify what we want to find in the response message
tests["Body matches string"] = responseBody.has('"statusCode":200'), Determine whether the response body contains :"statusCode":200
We need to parse JSON Yes , stay SNIPPETS Find ” Response body:JSON value check” And click the , Assertion code is added automatically
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
tests["response statusCode"] = jsonData.statusCode === 200; // Judge statusCode The value of is 200
tests["response message"] = jsonData.message === 'Success'; // Judge message The value of is ” Success”
边栏推荐
- 消息称腾讯正式宣布成立“XR”部门,押注元宇宙;谷歌前 CEO:美国即将输掉芯片竞争,要让台积电、三星建更多工厂...
- With its own cells as raw materials, the first 3D printing ear transplantation was successful! More complex organs can be printed in the future
- Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable
- Ribbon source code analysis @loadbalanced and loadbalancerclient
- 云计算发展的 4 个阶段,终于有人讲明白了
- 物联网?快来看 Arduino 上云啦
- 伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
- DX12引擎开发课程进度-这个课程到底讲到哪里了
- 史上最全DPU厂商大盘点(上)
- Bytebase joins Alibaba cloud polardb open source database community
猜你喜欢
随机推荐
What are the problems with traditional IO? Why is zero copy introduced?
Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable
海泰前沿技术|隐私计算技术在医疗数据保护中的应用
红象云腾完成与龙蜥操作系统兼容适配,产品运行稳定
Coinbase will launch the first encryption derivative for individual investors
得物多活架构设计之路由服务设计
Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
Popupwindow touch event transparent transmission scheme
Can the OPDS SQL component pass process parameters to the next component through context
C langage pour le déminage (version simplifiée)
"Super point" in "Meng Hua Lu", is the goose wronged?
Vxlan and MPLS: from data center to Metro Ethernet
Bean lifecycle flowchart
I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably
Camera rental management system based on qt+mysql
The four stages of cloud computing development have finally been clarified
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
2022年最新四川建筑八大员(电气施工员)模拟题库及答案
Wechat applet custom tabbar