Python 、Jmeter、Locust 如何生成大量不重复的数据?
1、Jmeter的 beanshell PreProcessor
系统时间加上线程号,保证数据不重复
vars.put(“变量A”,Thread.currentThread().getId() + ‘-’ +System.currentTimeMilss()+"")
引用${变量A} 使用Debug Sampler查看生成的响应数据
2、Python
random.sample(string.digits+string.ascii_letters, length)-----生成固定长度的不重复字符串
若是注册类的手机号:
查找数据库里最大的电话号码,每次注册都传参:最大号码+1
sql = “select max(mobilephone) from member”
cursor=db.cursor
cursor.execute(sql)
mobilephone_max = cursor.fetchone()
mobilephone = str(int(mobilephone_max[0])+1)
3、Locust
注册类手机号生成
from locust import HttpLocust,TaskSet,task
import