当前位置:网站首页>Response assertion of JMeter interface test
Response assertion of JMeter interface test
2022-07-19 02:36:00 【Insomnia book】
One 、 What is the assertion
1. The function of assertion
Assertions are used to execute Examination of results , And process after each sampler in the same range . If you want to assert a sampler , Simply add assertions to a subset of the sampler .
2. Why use assertions ?
JMeter as well as Postman And other interface testing tools , They all work on the basis of agreements , Use these tools to send requests , When the request is sent successfully ( That is, the protocol is sent successfully ), Request the sample to display green in the view result tree . For example, the agreement status code is 200 It's success , It only means that the protocol is sent successfully , But business is not necessarily successful . It is possible that the protocol was successfully sent , But the business did not succeed , however JMeter Default no judgment . So want to Verify whether the business succeeds or fails , You have to assert , The assertion is based on the response of the interface , Generally, it mainly asserts business status codes and messege Etc .
Two 、 How to judge JMeter Response assertion succeeded ?
3. Take a chestnut
JMeter Assert success , stay View the result tree The request in is green , I can't see the information of asserting success .
JMeter When the assertion fails , It is displayed in red in the view result tree , You can see the information of assertion failure .
Response assertion settings 
3、 ... and 、 Jmeter The explanation of the assertion page
4. Apply to
Assertions can be applied to the main sample , Subsample or both . The default assertion is the second , Assertions apply to the main sample .
① Main sample and sub-samples: Master sample and subsample
② Main sample only: Master sample only , Be careful : Usually, only one request is triggered when a request is issued , So check “main sampie only” Can ; If you send a request, you can trigger multiple server requests , There is main sample and sub-sample It's too late
③ Sub-samples only: Subsamples only
④ JMeter Variable Name to use:JMeter Use variable names , Assertions will be applied to the contents of named variables
Instructions :
In general , Use the master sample directly ( Default ) The assertion of . Because most of the time , Only the main request will have the necessary assertion data , But the front end JavaScript Language , There are two frames ajax and jquery A single request can generate multiple sub requests internally , And each request will have response data , So , Most of the time , Asserting the main sampler is sufficient .
If you choose Main sample and sub-samples, Then the assertion is to verify the response of the main sampler and the sub sampler , Take a look at the results , Except that the response of the main sampler contains “ Log out ”, The response of other sub samplers did not “ Log out ”, So it will assert failure , The others are the same .
So let's talk about that JMeter Variable Name to use:JMeter Use variable names , Assertions will be applied to the contents of named variables . I tried , It can be used in this way , If there is something wrong, please ask .
The assertion is correct , If the variable name in the regular is inconsistent with the variable name in the assertion , Assertions fail .
5. Response fields to test
① General http Respond to , Check all “ The response text ”
②url The sample is right sample Of url To assert that , If the request is not redirected , Just ask for url, If there is a redirection , Just ask for url Redirection url
③ Response code :http Response code , Such as 101,200,302,404,501 When we want to verify 404,501 etc. http Response code , You need to check “ ignore status” Because when http The response code is 400,500 when ,jmeter By default, this request fails
④ Response information : Response information corresponding to the response code , for example “OK"
6. Pattern matching rules (Pattern Mactching Rules)
① Include : The returned result includes the specified content , Support regular matching
Take a chestnut :
The response of the interface is 
To assert that , Assertion passed 
② matching : And Equals Almost the same as , All assertions must be completely consistent with the return value . The difference is , Regular is supported here , When writing regular expressions , Regular expressions should also match the return value exactly , To be able to pass
③Equals( equal ): The returned result is completely consistent with the assertion you specified , Regular matching is not supported . Attention is exactly the same , There is only one special case that will be used , Rarely used
④SubString( character string ): And “ Include ” The function is similar to , The difference is , Regular matching is not supported
⑤ no : conversely , Not It means
⑥ perhaps : Can be multiple values , Available below , For example, there may be two different judgment values in an assertion , You can choose to use , When a requirement is met , Even if it succeeds . This function can be used in many ways , Like the example above , More assertions
7. Test mode
Enter the value to match ( You can't have Spaces )
8. Custom failure message (Custom failure message)
When it is judged that the return value is wrong , What information is returned . It can be displayed in the assertion result 
You can see the information of the assertion just filled in in the view result tree , Does not match the entered expectations , It is judged that the task failed , View the result tree and mark the task result in red 
边栏推荐
- 并发虚拟用户、RPS、TPS的解读
- STL -- string container
- Performance test implementation specification Guide
- [tools] unity screen drawing line, unity screen drawing Hsj drawing tool
- [tools] unity quickly starts to make the artifact tilemap of 2D and 2.5D games
- Array Transformer-分块思想
- 项目性能优化实战:解决首页白屏问题,自定义 loading 动画优化首屏效果
- Server knowledge (details)
- GoReplay
- Unity notes 1
猜你喜欢

Attack and defense world - easytornado notes

Decentralized edge rendering meta universe protocol cadeus was invited to attend the cbaia 2022 summit to enable more Web3 application scenarios with technology

Cocoon breaking and rebirth of 3D NFT: caduceus decentralized edge rendering technology

Bugku---- regular matching, cookies

新手如何配置多个 SSH Key(通俗易懂手把手教学)

jmeter连接数据库的方法

Visual studio 2019-qt debugging

Network layer transmission protocol (detailed)

转载:SQL注入常见绕过
![[unity Editor Extension] unity makes its own exclusive editor panel](/img/67/12a4ab5167d4a5fc2aaba5220c8df9.png)
[unity Editor Extension] unity makes its own exclusive editor panel
随机推荐
Injection de modèles ssti
STL -- stack container
Dirty reading, unreal reading, non repeatable reading
Tree array and St table
深入性能测试数据分析
Jmeter接口测试之响应断言
服务器知识(详情)
STL -- map container
性能瓶颈定位XMind
Visual studio 2019-qt debugging
【Antv G2】折线图如何添加点击事件(点击任意位置即可获取折线上点的值)
逻辑漏洞---登录验证码安全
[unity Editor Extension] unity makes its own exclusive editor panel
sqlmap的使用
[tools] unity2d character controller, which controls 2D players to move and jump in four directions and horizontal directions
jmeter连接数据库的方法
[tools] unity quickly starts to make the artifact tilemap of 2D and 2.5D games
逻辑漏洞----身份验证漏洞
bugku题解
Bugku problem solution