如何以编程方式从Jmeter生成响应时间图
我有以下Java代码来运行JMeter。
import org.apache.jmeter.control.LoopController;import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
public class HCTGameDay {
public static void main(String[] args){
// Engine
StandardJMeterEngine jm = new StandardJMeterEngine();
// jmeter.properties
JMeterUtils.loadJMeterProperties("/Users/rokumar/Desktop/jmeter.properties");
HashTree hashTree = new HashTree();
// HTTP Sampler
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain("www.linkedin.com");
httpSampler.setPort(80);
httpSampler.setPath("/");
httpSampler.setMethod("GET");
// Loop Controller
TestElement loopCtrl = new LoopController();
((LoopController)loopCtrl).setLoops(1);
((LoopController)loopCtrl).addTestElement(httpSampler);
((LoopController)loopCtrl).setFirst(true);
// Thread Group
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(1);
threadGroup.setRampUp(1);
threadGroup.setSamplerController((LoopController)loopCtrl);
// Test plan
TestPlan testPlan = new TestPlan("HCT TEST PLAN");
hashTree.add("testPlan", testPlan);
hashTree.add("loopCtrl", loopCtrl);
hashTree.add("threadGroup", threadGroup);
hashTree.add("httpSampler", httpSampler);
jm.configure(hashTree);
jm.run();
}
}
我在控制台输出中没有得到任何结果。响应时间等存储在哪里,以及如何以编程方式绘制响应时间,连接数和用户数的图表。
回答:
jm.configure(hashTree)
在行前添加以下代码
//add Summarizer output to get test progress in stdout like:// summary = 2 in 1.3s = 1.5/s Avg: 631 Min: 290 Max: 973 Err: 0 (0.00%)
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
// Store execution results into a .jtl file
String logFile = jmeterHome + System.getProperty("line.separator") + "example.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(hashTree.getArray()[0], logger);
它将example.jtl
在您的JMeter安装目录的/ bin文件夹中生成文件,这是适用于分析,图形生成等的常规JMeter结果文件。
请参阅https://bitbucket.org/blazemeter/jmeter-from-
code/上的5种不使用JMeter
GUI的方式启动JMeter测试的指南中的第4.3章,以详细了解如何从常规代码和示例类中的Java代码运行JMeter测试。特别供参考。
以上是 如何以编程方式从Jmeter生成响应时间图 的全部内容, 来源链接: utcz.com/qa/422761.html