[JMeter] threadNum: Assign the interface query result list to each thread in order

[Current Status of Software Testing Industry] Do you still dare to learn software testing in 2023? The future has been sent... Where should the testers go? [Automated testing, test development, performance testing]

When using JMeter for performance testing, you will encounter such a scenario: subsequent requests need to be assigned values ​​based on the previous query list results through the regular expression extractor, and the subsequent user assignments must be unique. How to do this?

From a programming perspective, this problem is not difficult. Just save the previous results to an array variable, and subsequent users (that is, individual threads in the thread group) can get values ​​from the array variable one by one.

The little chief had the same idea at first, but in the end he found that it was very complicated to implement this function. If you don’t believe it, you can give it a try. If there is a simple way to implement it, you can leave a message and tell Xiao Qi.

Finally, Xiao Sheik finally solved the above problem easily through the __threadNum function.

Let’s talk about the specific ideas

1. If the query list results of our previous request are as follows:

2. At this time, 3 users (threads) need to be used to execute the test and iterate for one round.

3. We create a new [http request] in JMeter to implement the request query list

4. Use the regular expression extractor to obtain the value of the query result (see the previous article for the specific usage of this extractor)

5. Create a new [JAVA request] with the name directly ${ID} (that is, the variable with the value above) so that we can check the results later.

6. Finally add a listener [Query Result Tree]. After running (as shown below) we see that the values ​​of the three users (threads) are the same.

 

The first thing you may think of here is to process the values ​​​​of the previous query list results, but as mentioned earlier, Xiaoqiu tried to implement it very complicatedly. Look carefully at the screenshot above. Each thread in the thread group has a number (such as thread group 1-3). Can we find a way to do this?

7. In the regular expression extractor, use ${__threadNum} as the value to match the number.

8. Finally, let’s run it again and see the value results (as shown below), which perfectly solves the problem of assigning the interface query result list to each user in order to ensure that each user assigns a unique value.

 

Consider some questions:

In reality, our query list request will also bring page (number of pages) and PageSize (number of paging entries). At this time, our user (thread) must ensure that the value is unique. How to assign values ​​to PageSize and the number of threads?
If we want to ensure that the value of each user (thread) in each round is unique, how should page be used?
In a performance testing scenario, what should I do if the query list result data is insufficient? .

The following are supporting learning materials. For those who are doing [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you!

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

 

How to obtain documents:

This document should be the most comprehensive and complete preparation warehouse for friends who want to engage in [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you!

Guess you like

Origin blog.csdn.net/2301_76643199/article/details/133172390