首页 > 其他分享 >JMeter Assertion

JMeter Assertion

时间:2023-03-24 14:33:05浏览次数:63  
标签:请求 text Assertion sample 响应 only JMeter sub

 

Response Assertion  (响应断言)

用于判断接口请求的响应结果是否符合预期的一种断言方式。

 

Apply to:

  • Main Samples and Sub Samples: JMeter will check for the 'expected text' to be present in both main and sub samples and if any of the samplers do no have the text, it fails.
  • Main Sample Only: - JMeter will check for the 'expected text' only in the main sample. It fails if it is not found.
  • Sub Sample only: - JMeter will check for the 'expected text' only in all the sub samples. All the sub samplers are expected to have the text. Otherwise it fails.
  • Main sample and sub-samples:匹配范围为当前主请求,及子请求;
  • Main sample only :仅当前主请求;
  • Sub samples only:仅子请求;
  • JMeter Variable:变量值进行匹配;
  • 关于应用范围,我们大多数勾选“main sample only” 就足够了,因为我们一个请求,实质上只有一个请求。但是当我们发一个请求时,可以触发多个服务器请求,类似于ajax那种,那么就有main sample  和 sub-sample之分了。 此外,对于有重定向的请求,并且勾选了“跟随重定向”, 那么这两个请求都是 sub-sample,重定向后的请求(第二个请求)就是main-sample。

Field to Test:

  • Text Response  响应文本:响应服务器返回的文本内容,http协议排除header部分;
  • Response Code 响应代码:匹配响应代码,比如http请求中‘200’代表成功;
  • Response Message  响应信息:匹配响应信息,处理成功返回‘成功’或者“ok”字样;
  • Response Header 响应头 :匹配响应头中的信息;
  • Request Headers 请求头 ;
  • URL Sampled :是对sample的url进行断言。如果请求没有重定向(302),那么就是这个就是请求url。 如果有重定向(且跟随重定向),那么url就包含请求url 和 重定向url;
  • Document(Text):一切Apache Tika 支持服务器响应,包括文本响应,还支持 PDF, Office, Audio, Video formats。jmeter会用Apache Tika 去解析服务器响应内容,会很耗内存,而且也很容易解析失败。所以一般普通http请求,不要选择这个;
  • Ignore Status:当我们要验证404,501等http响应代码时,需要勾选“ ignore status”。因为当http 响应代码为400,500时,jmeter默认这个请求时失败的;
  • Request Data:请求数据

Patterns Matching Rules:

  • Contains:响应内容包括需要匹配的内容就算成功;
  • Matches:响应内容要完全匹配匹配内容,不区分大小写;
  • equals:完全相等,区分大小写;
  • substring:响应内容包括匹配内容即为成功。
  • Not:勾选上之后,会对前面选择的进行反转。比如Matches + Not 就是不匹配就算Pass;
  • Or :添加多个匹配内容时,会用到。

Patterns to Test:匹配内容

Custom failure message:当断言判断当前请求失败时,显示信息。

 

Duration Assertion(响应时间断言)

是一种响应时长的断言

Apply to:

  • Main Samples and Sub Samples: JMeter will check for the 'expected text' to be present in both main and sub samples and if any of the samplers do no have the text, it fails.
  • Main Sample Only: - JMeter will check for the 'expected text' only in the main sample. It fails if it is not found.
  • Sub Sample only: - JMeter will check for the 'expected text' only in all the sub samples. All the sub samplers are expected to have the text. Otherwise it fails.

Duration to Assert:

Duration in milliseconds:响应时长,单位ms,超过设定的时间时,判定当前请求失败。 

标签:请求,text,Assertion,sample,响应,only,JMeter,sub
From: https://www.cnblogs.com/xiaobingdiaoyu/p/12925225.html

相关文章

  • 【jmeter】启动报错Uncaught Exception java.lang.IllegalAccessError: class com.git
    1、问题  之前是java8的时候装的jmeter突然不能用了,报错UncaughtExceptionjava.lang.IllegalAccessError:classcom.github.weisj.darklaf.ui.filech...... 2、......
  • jmeter常用的命令行及参数
    一、运行方式分类GUI方式:图形界面方式运行CLI方式:commandline命令行,jmeter的脚本可以通过命令行用命令进行执行二、用命令行执行的优势:1、图形化界面运行的时候会占......
  • jmeter:结合while控制器实现性能测试
    一.场景1.导入时,导入操作的用户数比较少,但是单次导入的数据量较大2.导入文件一共有三步操作,上传-验证-导入,执行完当前操作才可以执行下一步操作。2.导入时,即使导入数据......
  • jmeter性能测试指标
    性能测试指标:制作脚本---设置场景(线程组、事务、集合点、思考时间等)--运行场景(命令行、远程方式)---在运行场景的同时监控性能指标,收集性能数据--出据性能测试报告 ......
  • JMeter+Jenkins分布式压测持续集成
     Jenkinsjob配置参数化构建运行分布式shell脚本:sh...生成测试报告配置生成html测试报告,需要安装插件HTMLPublisherJMeter性能脚本编写jmete......
  • jmeter操作数据库增删改查的注意事项
    一,场景1.在jmeter造数据后,可通过数据库查询数据库是否新增数据,判断脚本执行是否成功。2.有些数据新增不可重复,因此脚本执行后需要将新增的数据删除,才能再次执行脚本。二......
  • jmeter常用的命令行参数
    jmeter常用的命令行 jmeter常用的命令行参数:-n 表示非GUI模式运行-t 加载jmeter脚本,指定jmeter脚本的路径,即jmx文件的路径-l 设置测试结果文......
  • Jmeter构造测试数据之 身份证号码篇
        mportjava.util.*;StringBuildergenerater=newStringBuilder();MapareaCode=newHashMap();areaCode.put("北京市",110000);areaCode.put("天津市",1......
  • Jmeter构造测试数据之 根据身份证号码计算出当前年龄
       importjava.util.*;importjava.lang.*;Stringriqi=prev.getResponseDataAsString();//获取响应结果Stringyear=riqi.substring(6,10);//截取年份String......
  • Jmeter构造测试数据之 姓名、手机号码篇
    importjava.util.*;importjava.lang.*;Stringstr="${__RandomString(3,0123456789,)}";Stringstr_xing="${__RandomString(1,赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤......