Do you know several assertion methods commonly used in JMeter?

JMeter is a commonly used load testing tool that tests the load capacity and performance of the system by simulating multi-threaded concurrent requests. When conducting performance testing, assertions are a very important part and can help us verify the correctness of the test results. The following introduces several assertion methods commonly used in JMeter.

1. Response Assertion
Response Assertion is the most commonly used assertion method. It can check the HTTP response according to different conditions and determine whether it meets the expected results. For example, we can use Response Assertion to check whether the HTTP response contains a specific string, whether the return code is 200, etc.

Add Response Assertion assertion step in JMeter:

Select the Sampler of the HTTP request to which assertions need to be added in the test plan.
Right-click the Sampler and select Add -> Assertions -> Response Assertion.
In the Response Assertion window, configure the condition parameters that need to be checked, such as Response Code, Response Message, Response Data, etc.
Running the test script will check the HTTP response according to the configured conditions. If the conditions are not met, the test will be considered failed.
2. Duration Assertion
Duration Assertion is a time asserter that can check whether the response time of all requests is within the specified time range based on the defined time range. For example, we can use Duration Assertion to check whether the response time of a certain request is less than 1 second.

Add Duration Assertion assertion step in JMeter:

Select the Sampler of the HTTP request to which assertions need to be added in the test plan.
Right-click the Sampler and select Add -> Assertions -> Duration Assertion.
Set the response time range to be checked in the Duration Assertion window.
Running the test script will check the HTTP response time according to the configured conditions. If the conditions are not met, the test will be considered failed.
3. Size Assertion
Size Assertion is a size asserter that can check whether the response data of all requests is within the specified size range according to the defined size range. For example, we can use Size Assertion to check whether the data returned by a request is less than 100KB.

Add Size Assertion assertion step in JMeter:

Select the Sampler of the HTTP request to which assertions need to be added in the test plan.
Right-click the Sampler and select Add -> Assertions -> Size Assertion.
Set the response data size range to be checked in the Size Assertion window.
Running the test script will check the HTTP response data size according to the configured conditions. If the conditions are not met, the test will be deemed to have failed.
4. Beanshell Assertion
Beanshell Assertion is a customized assertion method. You can use Beanshell scripting language to write your own judgment logic. For example, we can use Beanshell Assertion to check that the HTTP response contains all keywords, or to check whether the response data satisfies a specific regular expression, etc.

Add Beanshell Assertion assertion step in JMeter:

Select the Sampler of the HTTP request to which assertions need to be added in the test plan.
Right-click the Sampler and select Add -> Assertions -> Beanshell Assertion.
Write custom conditional judgment logic in the Beanshell Assertion window.
Run the test script and the HTTP response will be checked according to the written script. If the conditions are not met, the test will be considered failed.
Summarize

The above are several assertion methods commonly used in JMeter. When conducting performance testing, reasonable use of assertions can help us verify the correctness of test results, and can also speed up problem troubleshooting and resolution. Different assertion methods are suitable for different test scenarios. Choosing the appropriate assertion method according to actual needs can make testing work more efficient.

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

insert image description here

Software testing interview applet

A software test question bank that has been used by millions of people! ! ! Who is who knows! ! ! The most comprehensive interview test mini program on the Internet, you can use your mobile phone to answer questions, take the subway, bus, and roll it up!

Covers the following interview question sections:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. Web, app, interface automation, 7. Performance testing, 8. Programming basics, 9. HR interview questions, 10. Open test questions, 11. Security testing, 12. Computer basics

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can help you too!  

Supongo que te gusta

Origin blog.csdn.net/nhb687095/article/details/132581806
Recomendado
Clasificación