我有一个已经在gui中定义的jmeter测试,例如this。
我正在从Java中自动运行此jmeter测试,我想从Java代码中设置${__P(threads)}
。
相关代码为:
public List<String> runJmxTest(String jmxFile, String jtlFile) throws IOException {
HashTree testPlanTree;
List<String> resultSet = new ArrayList<>();
// Initialize JMeter SaveService
SaveService.loadProperties();
JMeterVariables j = new JMeterVariables();
j.put("threads", "10");
// Load existing .jmx Test Plan
File in = new File(jmeterHome.getPath() + "/bin/testPlans/" + jmxFile);
try{
testPlanTree = SaveService.loadTree(in);
} catch (FileNotFoundException e){
resultSet.add("fail");
resultSet.add(e.toString());
return resultSet;
}
// set up custom result collector with summariser
Summariser summer = new Summariser("caos-mbm summariser");
collector = new myResultCollector(summer);
if(jtlFile != null){
if(!jtlFile.contains(".jtl")) {
String jtlTmp = jtlFile.concat(".jtl");
collector.setFilename(jmeterHome.getPath() + "/bin/testPlans/Output/" + jtlTmp);
} else {
collector.setFilename(jmeterHome.getPath() + "/bin/testPlans/Output/" + jtlFile);
}
}
testPlanTree.add(testPlanTree.getArray()[0], collector);
// Run Test Plan
jm.configure(testPlanTree);
jm.run();
resultSet.add("success");
resultSet.add(Double.toString(collector.getErrorPercent()));
return resultSet;
}
我尝试通过道具设置属性,将其添加到测试计划树,将jmeterproperties添加到jmetercontext。我无法获取它,但是。
任何建议将不胜感激。我也在这里浏览了很多看起来相似的帖子,但是这些解决方案对我来说不起作用或已停止实施。
答案 0 :(得分:0)
您使用了错误的类,请删除这些行:
curl --request POST -H "PRIVATE-TOKEN: ${GITLABAPI_TOKEN}" -H 'Content-Type: application/json' --data "{\"description\": \"`git log $(git describe --tags --abbrev=0)..HEAD --oneline`\"}" https://gitlab.unc.nc/api/v4/projects/${APP_GITLAB_NUMBER}/repository/tags/${CI_COMMIT_TAG}/release
并添加以下内容:
JMeterVariables j = new JMeterVariables();
j.put("threads", "10");
加载测试计划后和运行测试之前,您需要执行此操作。
还要确保将ApacheJMeter_functions.jar添加到项目CLASSPATH
有关使用JMeter API进行JMeter测试的更多信息:Five Ways To Launch a JMeter Test without Using the JMeter GUI