如何为Jmeter类创建对象(例如:SampleResult ..etc)

时间:2019-01-05 08:07:48

标签: jmeter

我正在尝试在Jmeter jsr223 Postpro中为简单的采样器执行以下代码,该采样器的响应时间始终> 2毫秒,但我的答案为0。我知道我可以使用prev.getTime() &它可以工作,但是为什么不喜欢下面的内容?..很好奇。

import org.apache.jmeter.samplers.SampleResult;    
SampleResult sr = new SampleResult();    
long time = sr.getTime();
log.info("Response time is -"+time);    

2 个答案:

答案 0 :(得分:0)

您正在创建新结果。此结果未连接到任何请求,因此使用0值初始化时间。

prev保留上一个请求及其时间。

答案 1 :(得分:0)

There is prev shorthand which stands for the parent SampleResult, if you want to print the time taken by the Sampler to the jmeter.log file - you should rather be using prev instead of creating a new instance of the SampleResult class

so your code needs to be amended as follows:

long time = prev.getTime();
log.info("Response time is -"+time);

Demo:

enter image description here

More information: Top 8 JMeter Java Classes You Should Be Using with Groovy