当前位置:网站首页>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”
边栏推荐
- 网络安全审查办公室对知网启动网络安全审查,称其“掌握大量重要数据及敏感信息”
- 苹果不差钱,但做内容“没底气”
- [performance tuning basics] performance tuning standards
- Vxlan and MPLS: from data center to Metro Ethernet
- IDEA Dashboard
- How to apply agile development ideas to other work
- [suggested collection] time series prediction application and paper summary
- 苹果、微软、谷歌不再掐架,今年要合力干一件大事
- The Google File System (GFS) learning notes
- Visitor model -- generation gap between young and middle-aged people
猜你喜欢

What does virtualization mean? What technologies are included? What is the difference with private cloud?

Agency mode -- Jiangnan leather shoes factory

Cooking business experience of young people: bloggers are busy selling classes and bringing goods, and the organization earns millions a month

Camera rental management system based on qt+mysql

字节、腾讯也下场,这门「月赚3000万」的生意有多香?

Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI

Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably

Dongyuhui is not enough to bring goods to "rescue" live broadcast

Sequential stack traversal binary tree

Apple doesn't need money, but it has no confidence in its content
随机推荐
Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably
Vxlan and MPLS: from data center to Metro Ethernet
VXLAN 与 MPLS:从数据中心到城域以太网
Intermediary model -- collaboration among departments
Internet of things? Come and see Arduino on the cloud
畅直播|针对直播痛点的关键技术解析
二叉树的基本性质与遍历
Builder mode -- Master asked me to refine pills
C language to realize mine sweeping (simple version)
Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?
虚拟化是什么意思?包含哪些技术?与私有云有什么区别?
Image panr
DAPP system customization of full chain hash game (scheme design)
【建议收藏】时间序列预测应用、paper汇总
传统的IO存在什么问题?为什么引入零拷贝的?
苹果不差钱,但做内容“没底气”
Bytebase加入阿里云PolarDB开源数据库社区
海泰前沿技术|隐私计算技术在医疗数据保护中的应用
Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI
Smooth live broadcast | analysis of key technologies for live broadcast pain points