JMeter: Assertion response assertion

1. The definition of assertion

Assertions are used to verify that the sampler request or corresponding response data returns the expected results. Can be seen as a way to verify that the test is as expected.

For interface testing, it is to test Request/Response, and assertions can be made for either Request or Response. But most of them are assertions on Response.

Common assertion elements in JMeter are as follows:

1. Response assertion

2.JSON Assertion

2. Response assertion

▲ Configuration items

Apply to:

1. In most cases, only the main sampler has all the required response data. However, many web applications use Ajax and JQuery technologies. A single request can generate multiple sub-requests internally, and each request has its corresponding response data.

For example, if you request a certain page, the js in the page will call other requests.

2. In the "Embedded Resources from HTML Files" item of the advanced settings of the HTTP request, check "Retrieve All Embedded Resources". When sending the request, the relevant embedded resources will be parsed, which will also cause the sampler to generate multiple subsamples. device.

Embedded resources include: images, applets, stylesheets, external scripts, frames/iframes, background images, background sound, etc.

3. If there is a redirected request and "Follow Redirects" is checked, the main sampler is the last returned URL request, and the first URL and all URL requests returned by the redirect are subsamplers.

For example, if you use http://www.sina.com.cn/ to access Sina, there will be a redirect:

● First request: GET  http://www.sina.com.cn/Redirect  return:
Location: https://www.sina.com.cn/

● Second request: GET  https://www.sina.com.cn/

The main sampler is the second request; the first and second requests are subsamplers.

● Main sample and sub-samples

Range includes main sampler and all subsamplers

● Main sample only

Range is limited to main sampler

●Sub-samples only

Scope limited to all subsamplers

●JMeter Variable Name to use

Scope includes JMeter variables used

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

Field to Test:

1.Text Response

Response text. For the HTTP protocol, it is 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, etc.

3.Response Message

Respond to the message. For the HTTP protocol, it is the reason phrase, such as OK, Not Modified, Not Found, etc.

4.Response Headers

Response header fields.

5.Request Headers

Request header fields.

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 with Apache Tika. Enabling this option will also seriously affect performance, so use it with caution.

8.Request Data

Request data. For the HTTP protocol, it is the message-body of the request (excluding the request line and header fields)

9.Ignore Status

The overall success of the sampler is determined by combining the result of the assertion with the existing response status.

When the Ignore Status checkbox is selected, the response status is forced to be successful before the assertion is evaluated.

The HTTP protocol is unsuccessful by default when returning status codes of 4xx and 5xx. Checking this option can be used to set the status to success before performing further checks.

Note that this will have the effect of clearing any previous assertion failures, so be sure to only turn this setting on 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 the pattern string (case sensitive)

Notice:

Contains and Matches modes support Perl5-type regular expressions; Equals and Substring modes use text strings and do not support regular expressions.

5.Not

Negate the result of the assertion.

6.Or

Combine multiple test patterns with a logical "OR".

Patterns to Test:

List of patterns to test. Each mode is tested individually. If a pattern fails, other patterns are not checked, and there is no difference between setting one assertion with multiple patterns versus setting multiple assertions with each pattern (assuming other options are the same).

Custom failure message:

Custom assertion failure information. That is, set the value of "Assertion failure message".

▲ Make assertions on requests

1. Assert request header fields

Select "Request Headers" in "Response fields to test"

2. Asserting the request URL address is discussed in 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, it includes the URL returned each time; 2
) If "Follow Redirects" is not checked in "HTTP Request", the assertion object only targets the request URL.

▲ Make assertions about the response

1. Assert response header fields

Select "Response Headers" in "Field to Test"

2. Assert response status code

Select "Response code" in "Field to Test"

3. Assert response reason phrase

Select "Response Message" in "Field to Test"

4. Assert response body

Select "Text Response" in "Field to Test"

▲Multi-mode assertions

In the "Patterns to Test" item, you can add multiple assertion patterns for testing. Multiple patterns can be logically combined using "AND", "OR" and "NOT":

1. Logical AND (and)

Multiple modes are logically combined by "and" by default.

2. Logical or (or)

When "Or" in "Pattern Matching Rules" is checked, multiple patterns are logically combined by "or"

3. Logical negation (not)

When "Not" in "Pattern Matching Rules" is checked, combine each pattern "Not" with "and" or "or" to assume that there are patterns p1, p2, p3,..., pn (priority not > and > or)

1) Only check "Not"

is equivalent to: (not p1) and (not p2) and (not p3) and ... and (not pn)

2) Check "Not" and "Or"

相当于:(not p1) or (not p2) or (not p3) or ... or (not pn)

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
 

Insert image description here

Guess you like

Origin blog.csdn.net/m0_58026506/article/details/132996514