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.
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-sampleabout main sample and sub sample, interested to see this posthttp://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 URLResponse 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, Foundhttp/1.1 Okhttp/1.1 302 FoundResponse Header: Response header information, such asServer:tengineDate:thu, Mar 09:43:52 GMTcontent-type:text/htmlcontent-length:260Connection:closelocation:http://www.baidu.com/404.html(3) Pattern matching rulesinclude: Return results include the content you specified, support regular matchFor example:Response field: Response textpattern matching rules: matchingassertions are: 1, invalid 2, [a-z]+when the return value is: {"MSG": "Channel Invalid."}, both assertions are OK and return truematch:(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 textpattern matching rules: matchingThe 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 Falsewhen 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 specifiedSubString: Similar to "include", refers to the return result including the content you specified, but SubString does not support regular stringFor example:Response field: Response textpattern matching rules: matchingassertions are: 1, invalid 2, [a-z]+when the return value is: {"MSG": "Channel Invalid."}, assertion 1 returns True, but assertion 2 returns falseNo: 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.
Note: Transfer from http://www.51testing.com/html/80/n-2430180.html
JMeter notes: An explanation of the response assertion