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);