1、添加自定義函數,增加 號碼生成函數 MobileGenerator和身份證生成函數IdCardGenerator
在package org.apache.jmeter.functions;中增加自定義函數,詳細參照代碼:https://gitee.com/hongyeao/jmeter-hh
2、導入自定義jar
(1)創建字符串截取方法

1 package com.example.Controller; 2 3 public class TestJar { 4 public String doAppend(String mobile){ 5 String newmobile = ""; 6 newmobile = mobile.substring(0,3); 7 return newmobile; 8 } 9 10 }
(2)設置要導出的jar文件:File->project Settings->Artifacts,點擊添加jar
(3)導出jar:選擇build->build Artifacts即可導出
(4)把jar放入lib目錄,即可在jmeter中引入:
import com.example.Controller.*; TestJar testJar = new TestJar(); String newmobile =testJar.doAppend("123456789"); vars.put("newmobile",newmobile);