官網下載了apache-jmeter-3.3,配置環境變量,固然jdk要事先配好。java
通常用來測試併發和接口壓力測試,因爲工做須要用到以上需求,因此去了解下,而且記錄下apache
其餘基本使用就不介紹了,說下怎麼寫自定義函數吧,業務上模擬http下單請求,由於下單信息須要作加密,單一的參數提交已經不能實現需求,因此用到java代碼來實現併發
======源代碼=====app
public class MySignFunc extends AbstractFunction {ide
private static final List<String> desc = new LinkedList<String>();
private static final int MAX_PARA_COUNT = 8;
private static final int MIN_PARA_COUNT = 8;
static {
desc.add("輸入appId");
desc.add("輸入appSecret");
desc.add("輸入phone");
desc.add("輸入flowVal");
desc.add("輸入scope");
desc.add("輸入outOrderId");
desc.add("輸入callbackUrl");
desc.add("輸入timestamp");
desc.add("輸入testModel");
}
private Object[] values;
//function名稱
private static final String KEY = "__MySignFunc";
private String signStr = "";
@Override
public List<String> getArgumentDesc() {
// MyTask Auto-generated method stub
return desc;
}函數
@Override
public String execute(SampleResult arg0, Sampler arg1)
throws InvalidVariableException {
// MyTask Auto-generated method stub
String appId = ((CompoundVariable) values[0]).execute();
String appSecret = ((CompoundVariable) values[1]).execute();
String phone = ((CompoundVariable) values[2]).execute();
String flowVal = ((CompoundVariable) values[3]).execute();
String scope = ((CompoundVariable) values[4]).execute();
String outOrderId = ((CompoundVariable) values[5]).execute();
String callbackUrl = ((CompoundVariable) values[6]).execute();
String timestamp = ((CompoundVariable) values[7]).execute();
String testModel = ((CompoundVariable) values[8]).execute();
HashMap<String, String> params = new HashMap<>();
params.put("appId", appId);
params.put("phone", phone);
params.put("flowVal", flowVal);
params.put("scope",scope);
params.put("outOrderId", outOrderId);
params.put("callbackUrl",callbackUrl);
params.put("timestamp", timestamp);
params.put("testModel", testModel);
String signStr =MapUtils.createLinkString(params)+appSecret;
String sign = EncryptUtils.md5(signStr);
return sign;
}工具
@Override
public String getReferenceKey() {
// MyTask Auto-generated method stub
return KEY;
}開發工具
@Override
public void setParameters(Collection<CompoundVariable> arg0)
throws InvalidVariableException {
// MyTask Auto-generated method stub
values = arg0.toArray(); //將值存入類變量中
}測試
}
加密
導出jar包。放到\lib\ext下,重啓jmeter,就會看到本身寫的函數啦
輸入對應的值,點擊生成測試值是否正確,固然,值是變量來的,否則函數就是去了意義,變量能夠採用 自定義用戶變量的值或者讀取數據文件的值,具體就不詳細描述了。