JMeter中BeanShell Sampler报错Method put...not found in class‘org.apache.jmeter.threads.JMeterVariables

时间:2024-03-24 16:55:23

建一个BeanShell Sampler,方便调试

JMeter中BeanShell Sampler报错Method put...not found in class‘org.apache.jmeter.threads.JMeterVariables

修改前:

long s = ${__time(/100000,)};
long y = ${__Random(1,100000,)};
long z = s+y;
vars.put("xxx_id",z); //类型转换成String

通过异常发现,Error in method invocation: Method  jmeter   put( java.lang.String, long ) not found in class‘org.apache.jmeter.threads.JMeterVariables‘

大胆猜测,put的value应该是String。验证猜想:

修改后如下 ,

类型转成string,就不报错了

long s = ${__time(/100000,)};
long y = ${__Random(1,100000,)};
long z = s+y;
vars.put("XXX_id",z.toString()); //类型转换成String