我正在尝试在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);
答案 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:
More information: Top 8 JMeter Java Classes You Should Be Using with Groovy