JMeter--Explanation of the response assertion

Source: Internet
Author: User
Tags response code

    1. Response assertion: Assertion checksum of the server's response

    • Application scope: Main Sample and Sub sample, main sample only, sub-sample only, JMeter variable

Regarding the scope of application, most of us tick "main sample only" is enough, because we have a request, essentially only one request. But when we send a request, we can trigger multiple server requests, like Ajax, then there is the main sample and Sub-sample.

In addition, for requests that have redirects, and the "Follow redirect" is checked, both requests are sub-sample, and the redirected request (the second request) is Main-sample

About main sample and sub sample, interested to see this post

Http://stackoverflow.com/questions/28214936/jmeter-in-which-scenario-i-can-use-main-sample-or-sub-sample-or-both-for-te

    • Response fields: Response text, Document (text), URL sample, response code, response information, Response header,ignore status

Response Text: server response Text, general HTTP response, all tick this.
Document (text): all Apache Tika Support server response, including text response, also supports PDF, Office, Audio, Video formats. JMeter will use Apache Tika to parse the server response content, will be very memory-intensive, but also easy to parse failure. So generally ordinary HTTP requests, do not select this.   
URL Sample: is an assertion of the URL of sample. If the request is not redirected (302), then this is the request URL. If there is a redirect (and follow the redirect), then the URL contains the request URL and the redirect URL  
Response Code:HTTP response code, such as 101,200,302,404,501. But when we want to verify the HTTP response code of 404,501, we need to tick "ignore status". Because when the HTTP response code is 400,500, JMeter defaults to this request when it fails.   
Response Information : The response information for the HTTP response code, for example: OK, Found  
http/1.1 Ok
http/1.1 302 Found
Response Header: response header information, such as  
Server:tengine
Date:thu, Mar 09:43:52 GMT
content-type:text/html
content-length:260
Connection:close
location:http://www.baidu.com/404.html

    • Pattern matching Rules

include: Return results include the content you specified, support regular match
For example:
Response field: Response text
pattern matching rules: matching
assertions are: 1, invalid 2, [a-z]+
when the return value is: {"MSG": "Channel Invalid."}, both assertions are OK and return true
match:
(1) equal to equals. When the return value is fixed, you can return a value to make an assertion with the same effect as equals
(2) regular match. Matches the return result with a regular expression, but must match all. That is, the regular expression must be able to match the entire return value, not part of the return value.
For example:
Response field: Response text
pattern matching rules: matching
The assertion is: 1, {"MSG": "Channel invalid."}  2. {"MSG": "[a-z]+ invalid."} , 3, [a-z]+
when the return value is: {"MSG": "Channel invalid."} , Assertion 1 2 is OK, assertion 3 is False
when the return value is: {"MSG": "Channel Invalid."}, assertion 1 3 is false and assertion 2 is OK.
The reason is that assertion 1 can only be used with equals, while assertion 3 matches only the return value part, not all matches.
Equals: The returned result is exactly the same as the assertion you specified
SubString: Similar to "include", refers to the return result including the content you specified, but SubString does not support regular string
For example:
Response field: Response text
pattern matching rules: matching
assertions are: 1, invalid 2, [a-z]+
when the return value is: {"MSG": "Channel Invalid."}, assertion 1 returns True, but assertion 2 returns false
No: It is equivalent to reverse. If the above assertion result is true, the final assertion result is false after the "no" is checked. If the above assertion result is false and the "No" is checked, the final assertion result is true.

JMeter--Explanation of the response assertion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.