JMeter notes: An explanation of the response assertion

Source: Internet
Author: User
Tags response code

Assertions are often used when we use JMeter for performance testing. JMeter provides a number of assertions that would have been written, but found that there are a lot of things in each assertion, so first write the response assertions that we often use.

The first time in the Cnblog to write things, will not be typesetting, I hope the talent pointing. if reproduced, please indicate the source

Response Assertion: assertion checksum of the server's response

(1) 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

(2) Response field: 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

(3) 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

The:

(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.

Reference documents:

Http://blazemeter.com/blog/how-use-jmeter-assertions-3-easy-steps

Http://www.51testing.com/html/12/252512-223704.html

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

JMeter notes: An 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.