In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
I. response assertion
1. What is response assertion?
The most commonly used assertion method in jmeter is "response assertion", which determines whether the result is correct by checking whether the request content of the sampler matches the specified string in the response result.
Response assertions are simple and practical and can solve most of the problems at work.
In particular, Request Headers and Request Data are added to the response assertion in the jmeter4.0 version, which makes it possible to assert the request header and the request body, which meets the diverse assertion requirements and is very convenient.
2. Use response assertions
The use of response assertions is very simple, and there are usually three points to pay attention to:
"response fields to test"
Refers to the location of the content we want to assert, which is divided into request and response, which can be selected according to the actual situation (the most commonly used is the response text)
Pattern matching rules (1 and 3 mentioned here correspond to the numbers in the figure above)
Controls how the "1" in the above figure matches "3"
"include"-1 includes 3, supports regularity; "match"-1 exactly matches 3, supports regularity
"Equals"-1 exactly matches the text content in 3, does not support regularity, and is case sensitive; "Substring"-1 includes text content in 3, does not support regularity, and is case sensitive
"No", "or"-used in conjunction with the previous four options for logical inversion, or, respectively.
"Mode to be tested"
Fill in what we want to assert here, you can add multiple patterns, you can use variables, text, and regular expressions (in "include" and "match" modes).
Jmeter video: https://edu.51cto.com/course/14305.html
II. BeanShell assertion
1. What is the BeanShell assertion?
BeanShell assertions can use beanshell scripts to perform assertion checking, and can be used for more complex personalized requirements, more flexible and powerful, but proficient in using beanshell scripts.
In addition to using beanshell's built-in variables, the assertion result is set mainly through Failure and FailureMessage.
Failure = false;- means the assertion is successful
FailureMessage = "." ;-Custom success information
Failure = true;- indicates that the assertion failed
FailureMessage = "." ;-Custom failure information.
Let's look at a simple example:
The script is as follows:
If ("200.equals ("+ ResponseCode) = = false)
{
/ / when the response code is not equal to 200, the assertion is set and the failure information is output.
Failure=true
FailureMessage = "Response code was not a 200 response code it was" + ResponseCode + "."
Print ("the return code is" + ResponseCode); / / this goes to stdout
Log.warn ("the return code is" + ResponseCode); / / this goes to the JMeter log file
} else {
/ / when the response code is equal to 200, the assertion is set successfully and the success information is output
Failure=false
FailureMessage = "Return true, and the response code was" + ResponseCode
}
}
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.