java函数不执行,从Java代码调用Jmeter函数时不执行

I'm using some jmeter functions in my jmx file.

When I run it from command line with jmeter tool, its running normally, executing the function and return a value.

When I run the java code , which load the same jmx file its taking a function as a string and don't return a value.

I have tested with several functions, Results are the same.

In jtl file I see something like this- ${__time(yyyy-MM-dd HH:mm:ss)}

Its my java code, its working normally when I don't have a functions:

StandardJMeterEngine jmeter = new StandardJMeterEngine();

JMeterUtils.loadJMeterProperties(jmeterPropertiesPath);

JMeterUtils.setJMeterHome(jmeterHomePath);

JMeterUtils.initLogging();

JMeterUtils.initLocale();

SaveService.loadProperties();

HashTree testPlanTree = null;

try{

log.info("loading testPlanTree");

testPlanTree = SaveService.loadTree(jmxFile);

JMeter.convertSubTree( testPlanTree );

}catch(IOException ex){

log.info("error loading file as tree");

log.info(ex.getMessage());

return;

}

jmeter.configure(testPlanTree);

jmeter.run();

解决方案

Your code looks good, just double check you have ApacheJMeter_functions.jar in your project classpath. The file is located under "lib/ext" folder of your JMeter installation.

You might also want to add ResultCollector to store your test execution results into .jtl file like:

Summariser summer = null;

String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");

if (summariserName.length() > 0) {

summer = new Summariser(summariserName);

}

ResultCollector logger = new ResultCollector(summer);

logger.setFilename("result.jtl");

testPlanTree.add(testPlanTree.getArray()[0], logger);

Check out Five Ways To Launch a JMeter Test without Using the JMeter GUI for more information on different approaches to JMeter test execution including using Java API to kick off and develop tests.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值