当前位置:网站首页>Idea of batch manufacturing test data, with source code
Idea of batch manufacturing test data, with source code
2022-04-23 16:42:00 【Test development Kevin】
The core idea of creating data
In the work of performance testing , We often encounter the need to create data , This work can let the development students cooperate , But it must depend on the face of the development students ! encounter nice The development of students naturally work smoothly , But when you meet development students who don't cooperate well , Coordination and leadership are often needed to facilitate this , This is more troublesome ! This paper simulates the scenario of creating data through the example of circular batch inserting data , What is provided is the dry goods needed to make data SQL Code ! This article assumes that the reader understands the basic sql How to write statements and stored procedures .
The core idea of creating data is very simple : Is to write stored procedures , Loop insert data
Create data instance
Here through to mock Insert data into the database to do demo demonstration :
First , Create a table api_record2, The field information is as follows :
CREATE TABLE api_record2(
id INT(11) PRIMARY KEY AUTO_INCREMENT,
app_name VARCHAR(30) DEFAULT 'test',
host_ip VARCHAR(30),
access_time DATETIME,
method VARCHAR(10),
url VARCHAR(1000),
api_data VARCHAR(1000),
return_value VARCHAR(1000),
INDEX index_app_name ( app_name )
);
The specific meaning of field information will not be explained here ( I believe you can guess the meaning of naming by looking at it , If you have any questions, please leave a message ),id It's the primary key ,app_name Indexed .
The next step is to write stored procedures , The code is as follows :
DELIMITER ;;
DROP PROCEDURE IF EXISTS `insertdata`;
CREATE PROCEDURE insertdata()
BEGIN
DECLARE i INT;
SET i=1;
WHILE(i<=10)DO
INSERT INTO api_record2 (app_name,host_ip,access_time,method,url,api_data,return_value) VALUES (CONCAT('test',FLOOR( 1 + RAND() * (100 - 1))),'127.0.0.1',NOW(),'post','/yourapp_mock/func2','{"user":"kevin","pwd":"123",}','ok');
SET i=i+1;
END WHILE;
COMMIT; # If it's big data , It is suggested to add a layer of circulation , hold commit Put it on the outside of this layer of circulation , Not to fail , Roll back all
END;;
DELIMITER ;
CALL insertdata();
Stored procedure statement analysis
DELIMITER ;; sentence ;;
delimiter yes mysql Separator , stay mysql The default separator in the client is a semicolon , In general , On the client command line , If a line SQL Command to “;” ending , After returning , Will execute this command . For example, when creating a stored procedure , Functions, etc , At this time, you need to enter all a section of commands , Finally, execute it at one time , At this point, the interpreter needs to pass delimiter To deal with it , Replace the semicolon with another symbol , Such as :“//” or “;;”, This explains the semicolon in the command , Realize the one-time execution of this command , Otherwise, an error will be reported , Unable to execute .
DROP PROCEDURE IF EXISTS `insertdata` If stored procedure insertdata There is , Give up execution
CREATE PROCEDURE insertdata() Create stored procedure
BEGIN The transaction start
END End of transaction
COMMIT Transaction submission
WHILE(i<=10)DO
insert sql sentence
SET i=i+1;
END WHILE;
Batch insert data core : Circular insert 10 statement , Statement implementation is almost consistent with circular statements in other languages
insert In the sentence CONCAT('test',FLOOR( 1 + RAND() * (100 - 1))) Indicates that the application name is :test start +1-99 The random number , The main purpose is to explain how to insert random data
insert In the sentence NOW() Indicates to get the current time
CALL insertdata(); Execute stored procedures
This is a simple example , But it has clearly explained the ideas and specific methods of creating data , I believe you can combine your business to write more complex sql Statement and then insert operation ! Originality is not easy. , If the article helps you, you are welcome to like and forward !
版权声明
本文为[Test development Kevin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231638236941.html
边栏推荐
- 05 Lua control structure
- Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
- 最詳細的背包問題!!!
- English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
- Regular filtering of Intranet addresses and segments
- 信息摘要、数字签名、数字证书、对称加密与非对称加密详解
- Creation of RAID disk array and RAID5
- Xinwangda: HEV and Bev super fast charging fist products are shipped on a large scale
- loggie 源码分析 source file 模块主干分析
- TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
猜你喜欢
Deepinv20 installation MariaDB
Hypermotion cloud migration completes Alibaba cloud proprietary cloud product ecological integration certification
批量制造测试数据的思路,附源码
Cartoon: what are IAAs, PAAS, SaaS?
The font of the soft cell changes color
Real time operation of vim editor
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
vscode如何比较两个文件的异同
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
随机推荐
Calculate pie chart percentage
Public variables of robotframework
面试百分百问到的进程,你究竟了解多少
JIRA screenshot
Force buckle - 198 raid homes and plunder houses
RAID磁盘阵列与RAID5的创建
Deepinv20 installation MariaDB
File system read and write performance test practice
七朋元视界可信元宇宙社交体系满足多元化的消费以及社交需求
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
On the security of key passing and digital signature
关于 background-image 渐变gradient()那些事!
最详细的背包问题!!!
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
最詳細的背包問題!!!
Installation and management procedures
文件系统读写性能测试实战
Modify the test case name generated by DDT
NVIDIA显卡驱动报错
建站常用软件PhpStudy V8.1图文安装教程(Windows版)超详细