当前位置:网站首页>Jmeter接口测试之常用断言
Jmeter接口测试之常用断言
2022-06-12 01:03:00 【小梧敲代码】
在接口测试中,我们需要检查请求处理结果是否正确。当请求的响应状态码为200,是否表时接口功能正常呢?显然是不正确的。
响应状态为200,只能表明服务处理了你的请求,同时进行了结果返回;但并不能代表处理的结果符合接口功能要求。
此时只有进一步的检查“响应数据”是否与接口说明中的一致;才能断定结果是否正确。
Jmeter提供了一个断言元件,实现检查接口测试中的响应数据是否符合预期,确保接口测试与预期的一致性。
注:本篇内容以“Jmeter快速创建接口测试脚本”请求为例。
1、响应断言
适用于:判断返回内容与预期结果的比对
步骤:在需要判断的“HTTP”请求接口上,右击“添加”\“断言”\“响应断言”。

例如,响应文本中含有“南京”,表示请求响应成功。
在“测试模式”中添加“南京”,点击“启动”图标,执行请求,查看结果树。可能到此有朋友感觉奇怪,怎么与未加断言时执行效果一致。
那再修改“响应断言”为“南京我爱你”,再次执行请求。

这时请求结果为红色表时请求执行结果与预期设置不同,未包括“南京我爱你”字符,证明此条接口用例执行失败。
下面对“响应断言”内容进行详细介绍。
APPly to:
Main sample and sub-samples:作用于主取样器及对应子取样器
Main sample only:仅作用于主取样器
Sub-samples only:仅作用于子取样器
JMeter Variable:作用于jmeter变量(输入框内可输入jmeter的变量名称)
测试字段:响应文本、响应代码、 响应信息、响应头部…
模式匹配规则:包括、 匹配、Equals、字符串、否、或者
测试模式:可以添加/删除需要判断的内容,按钮“添加”、“删除”进行指定内容的管理。
除响应断言外,还有其他断言。
2、大小断言
适用于:判断返回内容的大小。
步骤:在需要判断的“HTTP”请求接口上,右击“添加”\“断言”\“大小断言”。
APPly to:同“响应断言”
Response Size Field to Test(响应字段的测试范围):完整响应、响应头、响应的消息体、响应代码、响应信息。
Size to Assert:断言字节大小
响应字段可以通过查看结果树看到
根据返回响应消息体的大小设置断言值,一般什么大于多少字节,不采用=,因为数据是变化的,大多数会在一定范围内。
3、断言持续时间
适用于:判断请求的响应时间
步骤:在需要判断的“HTTP”请求接口上,右击“添加”\“断言”\“断言持续时间”。
APPly to:同“响应断言”
持续时间(毫秒):设置期时间的时间,例如预计3秒响应,即设置为3000,如果响应时间在3秒回返回,则断言成功,否则失败!
最后感谢每一个认真阅读我文章的人,下面这个网盘链接也是我费了几天时间整理的非常全面的,希望也能帮助到有需要的你!

这些资料,对于想转行做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助……
如果你不想一个人野蛮生长,找不到系统的资料,问题得不到帮助,坚持几天便放弃的感受的话,可以点击下方小卡片加入我们群,大家可以一起讨论交流,里面会有各种软件测试资料和技术交流。
| 点击文末小卡片领取 |
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
自学推荐B站视频:
零基础转行软件测试:25天从零基础转行到入职软件测试岗,今天学完,明天就业。【包括功能/接口/自动化/python自动化测试/性能/测试开发】
边栏推荐
- Nat. Comm. | supercomputing +ai: providing navigation for natural product biosynthesis route planning
- be based on. NETCORE development blog project starblog - (11) access statistics
- 功能测试如何1个月快速进阶自动化测试?明确这2步就问题不大了
- QApplication a (argc, argv) and exec() in the main function of QT getting started
- 2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]表示点i到点j的距离或者权重, 而在二部
- 一、Flutter 入门学习写一简单客户端
- Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security
- How to make scripts executable anywhere
- Lambda终结操作forEach
- C language structure - learning 27
猜你喜欢

模块八-设计消息队列存储消息数据的 MySQL 表格

Henan Zhongchuang - from cloud to edge, how edge computing enables data centers

Virtual human appears on the stage of the Winter Olympic Games, connecting elements of the meta universe

Go out with a stream

Detailed explanation of merge sorting

How does Kingview use the wireless host link communication module to remotely collect PLC data?

One article to show you how to understand the harmonyos application on the shelves

At the digital data nextionbi online conference, traditional enterprises showed their in-depth understanding of data analysis

Explore table component virtualization

How can functional tests be quickly advanced in one month? It is not a problem to clarify these two steps
随机推荐
System.CommandLine选项Option
[foreign enterprise test interview and written examination] share the whole process of 8 rounds of 30k+ foreign enterprise interview
Recurrent+Transformer 视频恢复领域的‘德艺双馨’
A day when the script boy won't be killed
System. Commandline option
About MySQL password modification failure
Streaming Data Warehouse 存储:需求与架构
Mysql database: introduction to database 𞓜 addition, deletion, modification and query
How to optimize the opening speed of website pages to improve the experience?
LabVIEW Arduino电子称重系统(项目篇—1)
be based on. NETCORE development blog project starblog - (11) access statistics
[answer] business use cases and system use cases are mixed together
Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform
Cuiyunkai, CEO of Gewu titanium Intelligent Technology: data value jump, insight into the next generation of change forces
Jeecgboot 3.1.0 release, enterprise low code platform based on code generator
Chapter V - Fund professional ethics
[answer] is ubiquitous language a pseudo innovation?
How can functional tests be quickly advanced in one month? It is not a problem to clarify these two steps
[tools] spacing JS measurement spacing
Sharing of Manta network parallel chain solutions by Hufu Research Institute