Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Several assertion methods commonly used in JMeter

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

 In the use of JMeter for performance testing or interface automation testing, a function that is often used is assertion. Assertion is equivalent to checkpoint. It is used to determine whether the response result returned by the system is correct, so as to help us determine whether the test passes.

 This article focuses on several commonly used assertions: response assertions, JSON assertions, BeanShell assertions

I. Responding to assertions

Response assertion is the most commonly used assertion method, it can assert the results of various return types, such as Test, html, application/json, etc. In the Sample that needs to be asserted, right-click "Add" Assertion "Response assertion

Apply to option Default, Main sample only

Common response text for test fields (asserting response results), response header (asserting response header files)

Pattern matching rules include (response result includes the content of assertion), equal (response result and assertion result are the same)

Test patterns can add parts of what you want to assert, and if included, you can add multiple.

Execute test, assertion passes green

Change the assertion to a field where the response result does not exist. The execution result shows red. The assertion result shows that the system response result does not contain the "test assertion" field.

2. JSON assertion

JSON assertions are also commonly used in test work, and can only be asserted for requests whose response results are in the form of applicaton/json.

Right-click on Sample to assert. Add Assertions. JSON Assertions.

We use json assertion, generally assert whether a field value is returned is what we need, so we need to write JSON PATH (will not write see how to write another article), the following figure using regular pattern matching returned results containing 40 is considered that the response results meet the requirements, assertion configuration and response results are as follows:

The following shows how to set the assertion when the assertion result is constant, as shown in the following figure.

BeanShell Assertion

BeanShell assertions support a variety of development languages, this article describes the use of java to write assertions, the advantage of using BeanShell assertions is that you can play freely, such as when the assertion fails, prompt the expected result, the actual result, or output the result to the log when it fails.

If you use inclusion matching, you only need to modify the expected result. The expected result needs to be written between double quotes, and the middle double quotes need to be added with\escape, as follows:

Use exact equality match, and when it fails, output the result to the log, this time correct the expected result, so it will output the response result to the error log, the code is as follows:

   If the article is helpful to you, happy ×× synchronization, convenient for everyone to consult, I will continue to launch articles related to testing, and share testing technology with you, each original article is carefully written, prevent plagiarism copy

QQ technical exchange group: Add group Please enter verification information 51CTO

              

** WeChat 2 ×××           

*××× Resources download, you can get the download address of various resources I share **

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report