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

The usage of JMeter parameterization _ _ CSVRead ()

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, in this chapter we will mainly learn about JMeter parameterization _ _ CSVRead ().

Concept:

Apache JMeter is a Java-based stress testing tool developed by Apache. Used for stress testing of software, it was originally designed for Web application testing, but later extended to other testing areas. It can be used to test static and dynamic resources, such as static files, Java applets, CGI scripts, Java objects, databases, FTP servers, and so on. JMeter can be used to simulate huge loads on servers, networks, or objects, testing their strength and analyzing overall performance from different stress categories. In addition, JMeter can perform functional / regression tests on applications and verify that your program returns the desired results by creating scripts with assertions. For maximum flexibility, JMeter allows you to create assertions using regular expressions.

The role of JMeter

1. You can perform stress and performance tests on HTTP and FTP servers, as well as on any database (via JDBC).

two。 Full portability and 100% pure java.

3. Full Swing and lightweight component support (precompiled JAR uses javax.swing.*) packages.

4. The full multithreaded framework allows simultaneous sampling of different functions through multiple threads and through separate thread groups.

5. The elaborate GUI design allows for fast operation and more accurate timing.

6. Cache and offline analyze / playback test results.

Configuration items:

Use a file alias:

If the file path is long, consider using a file alias to simplify writing. The method of use is:

First, define the file alias before using the parameter for the first time; later, get the data after calling the function

Aliases can be used instead of file names. Here is an example of using aliases:

Read data from different data files:

You can set up different threads to read different data files.

Suppose there are n threads, and prepare the corresponding n csv files: testdata1.csv

Testdata2.csv,..., testdatan.csv

Thread 1 reads data from testdata1.csv, thread 2 reads data from testdata2.csv

The data of.

Use ${threadNum} to get the thread number, and then splice it with the file name to form a dynamic.

As the first argument to the CSVRead function

${CSVRead (. / testdata$ {_ _ threadNum} .csv, 0)}

Examples are as follows:

Here, take the previously introduced API for querying the total amount of goods purchased as an example.

Parameterization steps:

1. Determine which request parameters in the interface parameters need to be parameterized. When designing test cases, we prepare data according to product number, commodity specification and commodity quantity, so we parameterize id,attr,number.

2. Save the test data in an external document with a file type of csv or txt-- >

.csv or .txt

Create a new testdata.csv, write a use case on one line, and separate multiple parameter values by default (do not write column headings):

Case1,9,226,3

Case2,226,1

Case3,9,1

Case4,9226

3. Call the _ _ CSVRead () function to get the data in the external data file

Tools-- > Function Helper Dialog, open "Function"

Helper ", select" _ _ CSVRead "in" Choose a function ".

After filling in the parameter values, click "Generate & Copy to Clipboard" to generate the function call statement:

Take the column values:

Id:

${_ _ CSVRead (C:\ Users\ Foreknew\ Desktop\ testdata.csv,1

)}

Attr:

${_ _ CSVRead (C:\ Users\ Foreknew\ Desktop\ testdata.csv,2

)}

Number:

${_ _ CSVRead (C:\ Users\ Foreknew\ Desktop\ testdata.csv,3

)}

Line break:

${_ _ CSVRead (C:\ Users\ Foreknew\ Desktop\ testdata.csv,n

Ext)}

4. Replace the written data in the request with the variables defined in step 3

Data-- > ${varName}

For example, ${attr}

5. Configuration parameterization

5.1 set the number of threads to the number of use cases

5.2 the number of circular control requests

Add a loop controller and set the number of cycles to the number of test cases.

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