When we perform API testing, WEB service, or other system module testing, you may need to obtain and record data from the database. The purpose of these tests is to examine the data specified in the database, or to add the specified data to the database , and this article will show how to check, update, or create new data using JMeter. You can implement more complex database interaction tests based on these examples.
In this blog post, we will use the following software:
- Jmeter 3.3
- MySQL 5.7.18 Community Edition
- Java8, when writing a blog, Java 9 has been released, but it is not recommended to use,--2018.3.1
The author has already shared to Baidu net disk, HTTPS://PAN.BAIDU.COM/S/1I5U58MP
When conducting the following experiments, ensure that the following conditions are met:
- MySQL database has been successfully installed and can be accessed normally
- There is an available account for MySQL
- Tools such as Java and JMeter are configured correctly
I. Configuring the database connection in JMeter
1. Download mysql-connector/j 5.1.42 driver, MySQL official download link: https://dev.mysql.com/downloads/connector/j/, download zip or. tar.gz can be 2. Unpack the Tarball
3. Copy xx to the JMeter installation directory under the Lib folder:
Second, configure the JMeter db Connection configuration
4. Start JMeter, add the JDBC Connection configuration element, how to: Thread Group----Add the configuration component-->jdbc Connection config. Used to configure JMeter connection parameters.
5. Fill in the necessary parameter information, note variable name is very important, must fill, cannot omit
6. Send data request, add JDBC Sampler
7. Configure the JDBC Request
- Add variable Name, it is recommended to add the first step
- Set the query type for the SQL statement, and Select statement indicates that the request will retrieve the data from the database.
- Set result variable name, which stores the values of all fields and fields returned from the database. This variable must be unique within the thread group. If this variable is used by more than one JDBC request, only the contents of the last query are stored.
- Create a new SQL statement, as shown in.
- The rest of the parameters can not be filled
8. Add a "View results tree" and run Test 9. Adding "response assertion" as a child element of the JDBC request
10. Add "BeanShell assertions" as child elements of the JDBC request
11. Add the following code to the BeanShell assertion:
If an error occurs, an assertion is displayed
How to use JMeter to construct MySQL test data in batches