1、新建线程组
总共30万条数据
2、创建jdbc链接
创建jdbc连接配置
配置mysql连接
需要在jmeter安装的路径\apache-jmeter-5.6.3\lib\ext 目录下添加mysql 驱动
3、创建jdbc请求
jdbc链接名称需要与上一步中的保持一致,同时添加insert语句
例如
INSERT INTO `test_student`(name, sex, card_number, birth_day, create_time, email, telephone, score) VALUES ('${randomFullName}', '${__Random(1,2,)}', '1${__Random(3,9,)}${__Random(100000000,999999999,)}', '${randomBirthday}', '${randomDate}', '${__RandomString(6,abcdefghijklnmopqrstuvwxyz,)}@${__RandomFromMultipleVars(163|126|qq|sina|189,)}.com', '1${__Random(3,9,)}${__Random(100000000,999999999,)} ', '${__javaScript(Math.round(Math.random()*100),)} ');
4、创建随机变量
编写脚本,例如
import java.util.Random; // 定义一些常见的英文名字、中间名和姓氏
def firstNames = ["John", "Michael", "James", "Robert", "William", "David", "Richard", "Charles", "Joseph", "Thomas"];
def middleNames = ["Lee", "David", "James", "Robert", "John", "William", "Michael", "Charles", "Richard", "Joseph"];
def lastNames = ["Smith", "Johnson", "Williams", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson"]; // 创建一个Random对象
Random rand = new Random(); // 随机选择一个名字、中间名和姓氏
def randomFirstName = firstNames[rand.nextInt(firstNames.size())];
def randomMiddleName = middleNames[rand.nextInt(middleNames.size())];
def randomLastName = lastNames[rand.nextInt(lastNames.size())]; // 拼接名字、中间名和姓氏,如果中间名不是必需的,可以条件性地添加
def randomFullName = "${randomFirstName} ${randomMiddleName} ${randomLastName}"; // 如果不想总是包含中间名,可以添加一些逻辑来决定是否包含
// 例如,以50%的概率包含中间名
if (rand.nextBoolean()) { randomFullName = "${randomFirstName} ${randomLastName}";
}// 将随机生成的英文名设置为JMeter变量
vars.put("randomFullName", randomFullName);
5、示例下载
https://download.csdn.net/download/khuangliang/89040941