Use jmeter for stress testing (3)

Source: Internet
Author: User

How to use external data in jmeter, jmeter also provides a series of components that are mostly included in configuration components, such as CSV Data Set config, random variable, and User-Defined variables. In addition, preprocessor> User parameters can also use custom variables.

Here I will focus on the usage of USER Parameters and CSV Data Set config.

User parameters can be set for each thread in the test plan or test plan. If the set parameters are smaller than the number of threads, these parameters will be reused.

Take Google as an example. If you want to search with different keywords, you can set the following in the user parameters:

1. Right-click [thread group], choose add> Preprocessor> User parameters, and add five users to the user parameter component. Then, add a variable [keyword]. You can enter the values corresponding to the five users.

2. Set the number of threads in the [thread group] to 5.

3. Modify the request named/search in the script. Change the value of the field named [Q] to $ {keyword}

User parameters can also be used to read CSV files. If the preceding example is used to read CSV files, you need

1. Create a new file named keyword.txt in the directory of apachejmeter.jar, where the content is a keyword for each row.

2. Set the number of threads in the [thread group] to 5.

3. For example, if you set the user and the variable value to "keyword"," user _1" is "cmd_stringfromfile(keyword.txt )}

4. Modify the request named/search in the script. Change the value of the field named [Q] to $ {keyword}

After the preceding operations, click Run> start. The number of threads in the upper right corner of jmeter increases from 0 to 5. After the execution, the number of threads becomes 0.

Note: In general, the number of threads is the same as the number of variables defined in USER Parameters unless you have special requirements.

I usually use USER Parameters to define some very important constants. For example, to read large-scale data, we can use CSV Data Set config. CSV Data Set config reads data from the specified CSV file by default. Each thread uses one of the data in sequence. If the number of threads is greater than the actual number of data, data is reused in order.

1. right-click [thread group], add> Configuration component> CSV Data Set config, and set filename to the path where the CSV file is stored. Variable names is the variable name and set it to keyword, delimiter is generally a comma, and the four selection boxes are generally set as needed.

2. Set the number of [thread groups] to "permanent" and the number of threads is 1.

3. Modify the request named/search in the script. Change the value of the field named [Q] to $ {keyword}

After the preceding operations, click Run> start. The number of threads in the upper right corner of jmeter increases from 0 to 1. After the execution, the number of threads becomes 0.

Of course, my example is relatively simple. It is a little complicated and often used in combination with the user name and password. When testing a large amount of data, it is impossible to use the same user to execute operations because of problems related to caching. Therefore, many users are required to execute the operations. CSV Data Set config is useful in this case; it is also useful when inserting data.

We already know how to use external data, but how can we ensure that every thread executes a defined keyword?

there are multiple ways to use listeners or assertions. These two components will be introduced later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.