import java.io.FileWriter
import java.io.Writer
import java.util.Random
import java.util.Arrays
FileWriter fstream = new FileWriter("D:\\Jmeter\\测试集_rita\\添加产品.csv",false)
// 1. 设置为true时,从第2行开始插入数据;设置为false时,从第一行开始插入数据。
// 2. 设置为true时,后面运行时不会覆盖原先的数据;设置为false时,会覆盖原先的数据。
BufferedWriter out = new BufferedWriter(fstream)
Object result=vars.getObject("pro_res")
log.info("结果是"+ result)
int len = result.size()
log.info("个数是"+ len)
String p_ids=""
String p_types=""
String p_grades=""
String p_commerce_types=""
String p_air_conditioning_types=""
for(int i=0i<leni++){
String p_id= result.get(i).get("product_id").toString()
String p_type=result.get(i).get("product_types").toString()
String p_type2 = p_type.replace(","," ") //写入文件时是以“,”区分单元格的,所以得替换原先的符号
String[] p_type3 = p_type2.split(" ")
String p_grade= result.get(i).get("grades").toString()
String p_grade2=p_grade.replace(","," ")
String[] p_grade3 = p_grade2.split(" ")
String p_commerce_type= result.get(i).get("commerce_types").toString()
String p_commerce_type2=p_commerce_type.replace(","," ")
String[] p_commerce_type3 = p_commerce_type2.split(" ")
String p_air_conditioning_type=result.get(i).get("air_conditioning_types").toString()
String p_air_conditioning_type2=p_air_conditioning_type.replace(","," ")
String[] p_air_conditioning_type3 = p_air_conditioning_type2.split(" ")
log.info("p_ids为" + p_id)
log.info("p_types为" + p_type2)
log.info("p_grades为" + p_grade2)
log.info("p_commerce_types为" + p_commerce_type2)
log.info("p_air_conditioning_types为" + p_air_conditioning_type2)
log.info("长度为" + p_type3.length)
log.info("长度为" + p_grade3.length)
log.info("长度为" + p_commerce_type3.length)
log.info("长度为" + p_air_conditioning_type3.length)
Random random = new Random()
int i = random.nextInt(p_type3.length)
int j = random.nextInt(p_grade3.length)
int k = random.nextInt(p_commerce_type3.length)
int l = random.nextInt(p_air_conditioning_type3.length)
out.write(p_id + ",")
if (p_type3.length == 1){
out.write(null + ",")//当属性为空时,需要传null
}else{
out.write(p_type3[i].toString() + ",")
}
if (p_grade3.length == 1){
out.write(null + ",")
}else{
out.write(p_grade3[j].toString() + ",")
}
if (p_commerce_type3.length == 1){
out.write(null + ",")
}else{
out.write(p_commerce_type3[k].toString() + ",")
}
if (p_air_conditioning_type3.length == 1){
out.write(null + ",")
}else{
out.write(p_air_conditioning_type3[l].toString() + ",")
}
}
out.close()
fstream.close()
用于检查测试中得到的响应数据等是否符合预期。先在jmeter中添加一个线程组。添加好线程组,在右键添加一个http请求。找到一个可用的接口测试一下。上边测试过可以用的网址,拿过来,填充进去。在断言里添加一个监听结果树,在添加一个聚合报告。
1、jmeter的架构和loadrunner原理一样,都是通过中间代理,监控和收集并发客户端发出的指令,把他们生成脚本,再发送到应用服务器,再监控服务器反馈结果的一个过程;\x0d\x0a2、分布式中间代理功能在jmeter中也有,这个分页式代理是指可设置多台代理在不同PC中,通过远程进行控制,即通过使用多台机器运行的谓的agant来分担load generator自身的压力,并借引来获取更大的并发用户数,loadrunner也有此功能;\x0d\x0a3、jmeter安装简单,只需要解压jmeter文件包到C盘上就可以了,不用安装,要是你想执行调试测试脚本,前提是:装上jdk和netbean插件,而loadrunner安装包有1G多,在一台P3.0,1G内存的PC上安装要一个多小时,要是装过旧的盗版还不能再装新版,解决办法倒是有,但麻烦且花时间;\x0d\x0a4、Jmeter没有IP欺骗功能,IP欺骗是指在一台PC上多个IP地址分配给并发用户,这个功能对于模拟较真实的用户环境来说,是较有用,loadrunner有此功能;\x0d\x0a5、jmeter也提供了一个利用本地proxy server(代理服务器)来录制生成测试脚本的功能,但是这个功能并不好用,测试对象的个别参数要手工增加上去,还得附带装个IE代理,如 GoogleToolbarDownloader这些插件来捕捉参数,但是有一个工具badbody,利用这个工具可以录制 *** 作,然后选择将脚本保存为jmeter脚本,然后利用jmeter可以打开并修改脚本;\x0d\x0a6、Jmeter的报表较少,对于要分析测试性能不足作为依据。如要知道数据库服务器或应用程序服务的cpu,money等参数,还得在相关服务器上另外写脚本记录服务器的性能;\x0d\x0a7、jmeter做性能测试,主要是通过增加线程的数目,或者是设置循环次数来增加并发用户,而loadrunner可以通过在场景中选择要设置什么样的场景,然后选择虚拟用户数;\x0d\x0a8、jmeter可以通过逻辑控制器实现复杂的测试行为,相当于loadrunner中的测试场景;\x0d\x0a9、jmeter可以做web程序的功能测试,利用jmeter中的样本,可以做灰盒测试,loadrunner主要用来做性能测试;\x0d\x0a10、jmeter是开源的,但是使用的人较少,网络上相关资料不全面,需要自己去揣摩,而loadrunner是商业软件,如果是正版本,有技术支持,同时,网络上的资料相当多;\x0d\x0a11、Jmeter的脚本修改,主要是针对jmeter中各个部件的熟悉程序,已经相关的一些协议的掌握情况,而不依赖于编程,而loadrunner除了复杂的场景设置外,还需要掌握函数,修改脚本。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)