询价接口压测,需要批量生成数据,
数据包括4个字段(车牌号,车架号,发动机号,支付号)licenseNo,vehicleFrameNo,engineNo,payFlowId
需符合LoadRunner 读取数据的格式
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Random; public class Pattern{ public static void main(String [] agrs) throws IOException{ File file = new File("D:\\testXml.txt"); if(!file.exists()){ try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } FileWriter writer; try { writer = new FileWriter(file); for (int i = 0; i < 10000; i++) { String payFlowId = "A"+getRandomString(14,"A"); String engineNo = "AWL"+getRandomString(3,"A")+getRandomString(1,"B")+getRandomString(5,"A"); String vehicleFrameNo = "LSV"+getRandomString(4,"A")+getRandomString(2,"B")+getRandomString(8,"A"); String licenseNo = "*"; System.out.println(licenseNo+","+vehicleFrameNo+","+engineNo+","+payFlowId); writer.write(licenseNo+","+vehicleFrameNo+","+engineNo+","+payFlowId+"\n");// 写内容 } writer.flush();// 清空缓冲区,立即将输出流里的内容写到文件里 writer.close();// 关闭输出流,施放资源 } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String getRandomString(int length,String flg) { //length表示生成字符串的长度 String baseall = "ABCDEFGHJKLMNPRSTUVWXY0123456789"; String base = "ABCDEFGHJKLMNPRSTUVWXY"; String intbase = "0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number; if("A".equals(flg)){ number = random.nextInt(intbase.length()); sb.append(intbase.charAt(number)); } else if("B".equals(flg)){ number = random.nextInt(base.length()); sb.append(base.charAt(number)); }else { number = random.nextInt(baseall.length()); sb.append(baseall.charAt(number)); } } return sb.toString(); } }