Essential knowledge for performance testing-Using MySQL stored procedures to construct large amounts of data: Example analysis

In the software development process, testing is an indispensable link. Through testing, we can discover and fix various problems in the software and improve the quality and stability of the software. However, manually writing large numbers of test cases is a time-consuming and error-prone task. In order to solve this problem, we need to learn to use batch data construction technology.

Batch data construction is an automated data generation technique that generates large amounts of test data based on predefined rules and patterns. These data can be used in various scenarios, such as functional testing, performance testing, security testing, etc. Compared with manually creating data, batch data construction has the following advantages:

1. Improve efficiency: Batch data construction can quickly generate large amounts of test data, saving time and energy in manually creating data.

2. Reduce errors: Since batch data construction is an automated process, the occurrence of human errors can be greatly reduced.

3. Repeatability: The data generated by batch data construction is repeatable and can be used in different test environments.

So, how to implement batch data construction? We use mysql stored procedures to construct large batches of test data. The following are examples

1. Member table structure:

CREATE TABLE `member` (
  `lv_id` int(255) NOT NULL AUTO_INCREMENT,
  `uname` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `passwd` varchar(255) DEFAULT NULL,
  `sex` int(11) DEFAULT NULL,
  PRIMARY KEY (`lv_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20002 DEFAULT CHARSET=utf8;

2. Write mysql stored procedure function

BEGIN
DECLARE i INT DEFAULT 0;
DECLARE p_name VARCHAR (255);
DECLARE p_email VARCHAR (255);
DECLARE p_sex INT;
WHILE i < 10000 DO
SET p_name = CONCAT('test_', i);
SET p_email = CONCAT('test_', i, '@qq.com');
IF i % 2 = 0 THEN
  SET p_sex = 0;
ELSE
  SET p_sex = - 1;
END
IF;
INSERT INTO member (uname, email, `passwd`, sex)
VALUES
  (
    p_name,
    p_email,
    'e10adc3949ba59abbe56e057f20f883e',
    p_sex
  );
SET i = i + 1;
END
WHILE;
END

3. Open the navicat tool

picture

picture

picture

picture

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

This information 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 also help you!

Guess you like

Origin blog.csdn.net/NHB456789/article/details/133078733