In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Assertions are used to verify that the sampler request or corresponding response data returns the desired result. It can be seen as a way to verify that the test is expected.
For interface testing, it is testing Request/Response, and assertions can be made against either Request or Response. But most of them make assertions about Response.
Common assertion elements in JMeter are as follows:
1. Response assertion
2.JSON Assertion
In this chapter, we first learn about JMeter response assertions.
Configuration item
Apply to:
1. In most cases, only the main sampler has all the necessary response data. However, many Web applications use Ajax,JQuery technology, a single request can generate multiple sub-requests internally, and each request has its corresponding response data.
For example, if you request a page, the js in the page will call other requests.
two。 In the "Embedded Resources from HTMLFiles" item of the advanced setting of the HTTP request, check "Retrieve All Embedded Resources", when the request is sent, the relevant embedded resources will be parsed, and the sampler may produce multiple sub-samplers.
Embedded resources include: images, applets, stylesheets, external
Scripts 、 frames/iframes 、
Background images, background sound, etc.
3. If there is a redirect request and "Follow Redirects" is checked, the main sampler is the last returned URL request
All URL requests returned by the first URL and redirect are child samplers.
For example, if you use http://www.sina.com/ to access Sina, you will have two redirects:
First request: GET http://www.sina.com/ redirect returned:
Location: http://www.sina.com.cn/
Second request: GET http://www.sina.com.cn/ redirect return
Back: Location: https://www.sina.com.cn/
Third request: GET https://www.sina.com.cn/
The main sampler is the third request; the first, second and third requests are subsamplers.
Main sample and sub-samples
The range includes the main sampler and all child samplers
Main sample only
The range is limited to the main sampler
Sub-samples only
The range is limited to all child samplers
JMeter Variable Name to use
The scope includes the JMeter variable used
Field to Test:
1.Text Response
Response text. For the HTTP protocol, the message-body of the response (excluding status line and header fields)
2.Response Code
Response code. For the HTTP protocol, it is the response status code, such as 200,304,404 and so on.
3.Response Message
Response message. For the HTTP protocol, it is a cause phrase, such as OK, Not Modified, Not Found, and so on.
4.Response Headers
Respond to the header field.
5.Request Headers
Request header field.
6.URL Sampled
The requested URL. For HTTP requests, if "Follow Redirects" is checked, the redirected URL is included.
7.Document (text)
Extract text from various types of documents through Apache Tika. Turning this option on can also seriously affect performance, so use it with caution.
8.Request Data
Request data. For HTTP protocol, the message-body of the request (excluding the request line and header field)
9.Ignore Status
The overall success of the sampler is determined by combining the result of the assertion with the existing response state.
When the Ignore Status check box is selected, the response status is forced to be successful before the assertion is evaluated.
The HTTP protocol does not succeed by default when returning the status codes of 4xx and 5xx. Check this box to set the status successfully before performing further checks.
Note that this will have the effect of clearing any previous assertion failures, so be sure to turn on this setting only on the first assertion.
Pattern Matching Rules:
1.Contains
True if the text contains a regular expression pattern
2.Matches
True if the entire text matches the regular expression pattern
3.Equals
True if the entire text is equal to the pattern string (case sensitive)
4.Substring
True if the text contains a pattern string (case sensitive)
Note:
Contains and Matches patterns support regular expressions of type Perl5
Equals and Substring patterns use text strings and do not support regular expressions.
5.Not
Negate the result of the assertion.
6.Or
Combine multiple test patterns with logical OR.
Patterns to Test:
List of patterns to test. Each pattern is tested separately. If the pattern fails, the other modes are not checked, and there is no difference between setting one assertion with multiple modes and setting multiple assertions with each pattern (assuming other options are the same).
Custom failure message:
Custom assertion failure message. That is, set the value of "Assertion failure message".
Make an assertion on the request
1. Assertion request header field
Select "Request Headers" in the response field to be tested
two。 Assertion request URL address
The discussion is divided into two situations:
1) if "Follow Redirects" is checked in "HTTP Request", the assertion object contains the request URL and the URL returned by the redirect Location header. If there are multiple redirects, the URL returned each time is included.
2) if "Follow Redirects" is not checked in "HTTP Request", the assertion object is only for the request URL.
Make assertions about the response
1. Assertion response header field
Select "Response Headers" in "Field to Test"
two。 Assertion response status code
Select "Response code" in "Field to Test"
3. Assertion response reason phrase
Select "Response Message" in "Field to Test"
4. Assertion response text
Select "Text Response" in "Field to Test"
Multimodal assertion
Multiple assertion patterns can be added to the "Patterns to Test" entry for testing, and multiple patterns can be logically combined using "and", "OR" and "not":
1. Logic and (and)
Multiple schemas are logically combined with "and (and)" by default.
two。 Logical OR (or)
When "Or" in "Pattern Matching Rules" is checked, multiple patterns are logically combined with "OR (or)"
3. Logical not (not)
When "Not" in "Pattern Matching Rules" is checked, each mode is Not followed by "and" or "or"
Suppose there is a pattern p1, p2, p2, p3, pn (priority not > and > or)
1) check only "Not"
It is equivalent to (not p1) and (not p2) and (not p3) and
.. And (not pn)
2) check "Not" and "Or"
Equivalent to: (not p1) or (not p2) or (not p3) or.
Or (not pn)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.