1. Jmeter進階三:把資料庫的結果處理後保存到本地的文件
import java.io.BufferedWriter;
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=0;i<len;i++){
String p_id= result.get(i).get("proct_id").toString();
String p_type=result.get(i).get("proct_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();
2. maven jmeter,jmeter 腳本放哪個目錄下
linux環境抄還是windows環境? 如果是linux環境,到襲bin目錄下:./jmeter.sh XX.jmx(所要運行的測試腳本,沒有的話,examples目錄下有個) 如果有進程啟動,且jmeter.log中沒有錯誤信息就安裝成功了; 如果是windows環境,雙擊「jmeter.bat」文件