当前位置:网站首页>JMeter 常用的几种断言方法,你会了吗?
JMeter 常用的几种断言方法,你会了吗?
2022-07-05 19:03:00 【小梧敲代码】
在使用Jmeter进行性能测试或者接口自动化测试工作中,经常会用到的一个功能,就是断言。断言是在请求的返回层面增加一层判断机制。因为请求成功了,并不代表结果一定正确,因此需要判断机制提高测试准确性。本文 主要介绍3种常用的断言:响应断言、JSON断言、断言持续时间。
一、响应断言(Response Assertion)
响应断言是最常用的一种断言方法,主要是对响应结果中的文本内容进行断言,比如响应结果是否包含指定的值,或者是否等于指定的值。响应断言可以适用各种返回类型的响应结果,如Test、html、application/json、application/xml等。
1、案例
发送请求:
http://www.hctestedu.com/
断言检查:检查响应结果中是否包含“柠檬班软件测试”的文本内容
2、操作步骤
第1步:添加线程组
第2步:添加HTTP请求
第3步:在HTTP请求下添加响应断言
第4步:添加断言结果和添加察看结果树
第5步:运行接口后,察看断言结果和察看结果树

二、JSON断言
JSON断言也是测试工作中经常用到的一种断言方法,它一般用于断言某个字段值是否等于我们指定的值。所以JSON断言只能针对响应结果为applicaton/json格式的进行断言操作。如果是其他类型(如:Test、html),则无法使用这种方式。
1、案例
发送请求:
http://47.115.15.198:7001/smarthome/user/login
–登录接口
断言检查:检查响应的数据中,user_name节点对应的内容是否为"lemonn"
2、操作步骤
第1步:添加线程组
第2步:添加HTTP请求
第3步:在HTTP请求下添加响应断言
第4步:添加断言结果和添加察看结果树
第5步:运行接口后,察看断言结果和察看结果树

三、断言持续时间(Duration Assertion)
断言持续时间通常用于做性能测试,一般用于检查HTTP请求的响应时间是否超过预期值。而这个响应时间是性能测试中常关注的一个性能指标。
1、案例
发送请求:https://www.baidu.com/
–百度官网接口
断言检查:检查响应时间是否小于200ms
2、操作步骤
第1步:添加线程组
第2步:添加HTTP请求
第3步:在HTTP请求下添加响应断言
第4步:添加断言结果和添加察看结果树
第5步:运行接口后,察看断言结果和察看结果树

最后感谢每一个认真阅读我文章的人,下面这个网盘链接也是我费了几天时间整理的非常全面的,希望也能帮助到有需要的你!

这些资料,对于想转行做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助……
如果你不想一个人野蛮生长,找不到系统的资料,问题得不到帮助,坚持几天便放弃的感受的话,可以点击下方小卡片加入我们群,大家可以一起讨论交流,里面会有各种软件测试资料和技术交流。
| 点击文末小卡片领取 |
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
自学推荐B站视频:
零基础转行软件测试:25天从零基础转行到入职软件测试岗,今天学完,明天就业。【包括功能/接口/自动化/python自动化测试/性能/测试开发】
边栏推荐
- 跨境支付平台 XTransfer 的低代码实践:如何与其他中台融合是核心
- Fuzor 2020软件安装包下载及安装教程
- shell编程基础(第9篇:循环)
- 2022全网最全的腾讯后台自动化测试与持续部署实践【万字长文】
- Blue sky drawing bed Apple quick instructions
- Debezium系列之:修改源码支持unix_timestamp() as DEFAULT value
- Talking about fake demand from takeout order
- [today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
- Hiengine: comparable to the local cloud native memory database engine
- UDF implementation of Dameng database
猜你喜欢
![2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]](/img/4b/90f07cd681b1e0595fc06c9429b338.jpg)
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]

Blue sky drawing bed Apple quick instructions

HiEngine:可媲美本地的云原生内存数据库引擎
Mysql如何对json数据进行查询及修改

Redhat7.4 configure Yum software warehouse (rhel7.4)

Low code practice of xtransfer, a cross-border payment platform: how to integrate with other medium-sized platforms is the core

Ten years at sea: old and new relay, dark horse rising

14、用户、组和权限(14)

Postman核心功能解析 —— 参数化和测试报告
![[performance test] jmeter+grafana+influxdb deployment practice](/img/32/f07792734d040829398a90a2040146.png)
[performance test] jmeter+grafana+influxdb deployment practice
随机推荐
Shang Silicon Valley Shang preferred project tutorial release
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
HAC集群修改管理员用户密码
Get wechat avatar and nickname with uniapp
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Emqx 5.0 officially released: a single cluster supports 100million mqtt connections
华为让出的高端市场,小米12S靠徕卡能抢到吗?
PG基础篇--逻辑结构管理(用户及权限管理)
使用文件和目录属性和属性
Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
Analysis of postman core functions - parameterization and test report
手机开户选择哪家券商公司比较好哪家平台更安全
[detailed explanation of AUTOSAR 14 startup process]
Ultrasonic ranging based on FPGA
XML basic knowledge concept
A cloud opens a new future of smart transportation
JAD installation, configuration and integration idea
word如何转换成pdf?word转pdf简单的方法分享!
Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
5. 数据访问 - EntityFramework集成