In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
JMeter
Apache JMeter is a Java-based stress testing tool developed by Apache. Used for stress testing software, it was originally designed for Web application testing, but later expanded to other testing areas. It can be used to test static and dynamic resources such as static files, Java servlets, CGI scripts, Java objects, databases, FTP servers, and more. JMeter can be used to simulate large loads on servers, networks or objects, test their strength from different stress categories and analyze overall performance. In addition, JMeter can do functional/regression testing on applications by creating scripts with assertions to verify that your application returns the results you expect. For maximum flexibility, JMeter allows you to create assertions using regular expressions.
JSON assertion
JSON is used to describe text data structures and has the following form:
1. object (object)
An object is an unordered set of name/value pairs. Objects begin with {(left braces) and begin with}(right braces)
End of brackets). Each name is followed by: colon,
Name/value pairs are separated by commas.
For example:
{"name":"zhangsan","sex":1,"age":25}
2. array (Array)
An array is an ordered collection of values. Array starts with [(left square brackets), starts with](right square brackets)
End of story. Values are separated by commas.
For example:
{
"man":[{"name":"zhangsan","sex":1,"age":21},
{"name":"lisi","sex":0,"age":18},
{"name":"wangwu","sex":0,"age":25}]
}
3. value (value)
Values can be strings, numbers, true/false, null, objects, or arrays.
4. String
A string is a sequence of zero or more Unicode characters, enclosed in double quotes,
Use backslashes to escape.
Characters are represented as a single string. Strings are very similar to strings in C or Java.
5. Number (number)
A series of numbers from 0 to 9, either negative or fractional. It can also be represented by e or E.
in exponential form;
Numbers are very similar to C or Java numbers, but do not use octal and hexadecimal formats.
6. white space
You can insert white space (spaces, newlines, carriage returns, horizontal tabs) between any pair of syntax symbols.
XPath is often used to parse, transform, and selectively extract data from XML documents. Like XPath, JOSNPath makes it easy to discover and extract data from JSON structures.
The "root member object" in JSONPath is always called $, whether it is an object or an array.
JSONPath expressions have two different presentation styles: "dot-notation"(. sign) and "bracket-notation"([] sign).
For example,
$.store.book[0].title or
$['store']['book'][0]['title']
JSONPath syntax element
JSONPath instance:
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
JSON asserts:
JSON assertions validate JSON documents returned by the server.
JSON assertions have two usage patterns:
1. According to whether JSONPath can find the path in the JSON document;
2. Extract and validate values according to JSONPath.
Assertion fails if document format is non-JSON;
If no path is found, the assertion fails;
The assertion fails if the extracted value is inconsistent with the expected value.
configuration items
Assert JSON Path exists:
The path of the JSON element used for the assertion (JSONPath).
1.Additionally assert value
Do you want to additionally verify the values extracted from JSONPath.
Uncheck to verify that JSONPath can find the path in the JSON document;
Check to verify that the values extracted from JSONPath are expected.
2.Match as regular expression
Expected value whether regular expressions can be used.
Unchecked, expected values cannot be expressed using regular expressions;
Check, expected values can be expressed using regular expressions.
Expected Value:
Expected value.
1.Expect null
Check if the value extracted by validation is null.
Here are two things to note:
a. Verify null value, or check "Additionally assert"
value", otherwise the verification is whether JSONPath can find the path;
b. Expected values are not filled in to indicate empty characters, which are not equivalent to null.
2.Invert assertion(will fail if above conditions met)
If checked, negates the assertion result.
Note:
In addition to null, there is also a special value, that is, an empty array. The expected value cannot be left empty.
Set to: []
application cases
Here, we will use the query total amount of purchased goods interface described earlier as an example to illustrate the use of JSON assertions.
The response data returned by this interface is JSON, so JSON assertions can be used.
Operation steps:
1. Parameterize the expected resultItem to verify here verify err_msg, resultWrite the expected result to csv file
For example:
case_name,goods_id,goods_attr,goods_num,error_msg,rs lt
case1,9,226,3,, ¥ 6630
Case2,226,1, The specified item was not found or the specified item attribute was not found.
Case3,9,1,, ¥ 2298
case4,9,226,, ¥ 2308
2. Add JSON Assertion and configure
JSON assertions can only assert one argument at a time, so you need to add multiple JSON assertions here.
Suppose you assert two return parameter values, the error message and the amount of the item.
{
"err_msg": "The specified item was not found or the specified item attribute was not found. ",
"result": "",
"qty": 1,
"err_no": 1
}
$.err_msg --> The specified item was not found or the specified item attribute was not found.
$.qty --> 1
JSON assertion configuration
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.