当前位置:网站首页>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自动化测试/性能/测试开发】
边栏推荐
- Breadth first search depth first search dynamic programming leetcode topic: delivering information
- 人们对于产业互联网的这样一种认识的转变,并不是一蹴而就的
- Practice of Flink CDC + Hudi massive data entering the lake in SF
- [foreign enterprise test interview and written examination] share the whole process of 8 rounds of 30k+ foreign enterprise interview
- Nat. Comm. | supercomputing +ai: providing navigation for natural product biosynthesis route planning
- Current situation investigation and demand forecast report of global and Chinese phenolic resin market, 2022 Edition
- Low code platform design exploration, how to better empower developers
- [answer] in the business sequence diagram of XX shopping mall, is it drawn as a business executor (bank) or a business entity (banking system)
- C language pointer and array - learning 23
- 【ROE】(2)ROE协议
猜你喜欢

Data visualization big screen - big screen cloud minimalist user manual

Flowable workflow

Intel trimbert: tailor Bert for trade-offs

【ROE】(2)ROE协议

flowable 工作流

Explore table component virtualization

Inventory: more than 20 typical safety incidents occurred in February, with a loss of nearly $400million

Characteristics of JS logical operators

ROS2之OpenCV基础代码对比foxy~galactic~humble

写代码复现论文的几点建议!
随机推荐
2022 edition of global and Chinese sodium hydrosulfide market in-depth investigation and prospect Trend Forecast Report
Lambda intermediate operation sorted
Henan Zhongchuang - from cloud to edge, how edge computing enables data centers
How to strengthen the prevention and control of major safety risks for chemical and dangerous goods enterprises in flood season
websocket服务器实战
深度学习100例 | 第41天:语音识别 - PyTorch实现
[foreign enterprise test interview and written examination] share the whole process of 8 rounds of 30k+ foreign enterprise interview
2022 edition of global and Chinese high purity silicon carbide powder operation research and investment strategy analysis report
be based on. NETCORE development blog project starblog - (11) access statistics
C language pointer - learning 22
Equipment encryption of industrial control security
How does Kingview use the wireless host link communication module to remotely collect PLC data?
Blue Bridge Cup - 2012b Group real question 3 specific drinking capacity
Investment analysis and demand forecast report of global and Chinese fluorosilicone industry in 2022
Characteristics of JS logical operators
【SignalR全套系列】之在.Net6中实现SignalR分组通信
Streaming Data Warehouse 存储:需求与架构
At the digital data nextionbi online conference, traditional enterprises showed their in-depth understanding of data analysis
Flink CDC + Hudi 海量数据入湖在顺丰的实践
Component introduction - large screen cloud minimalist user manual