我使用以下代码从java应用程序运行JMeter负载测试。
StandardJMeterEngine jmeter = new StandardJMeterEngine();
JMeterUtils.setJMeterHome(jmeterHome);
JMeterUtils.loadJMeterProperties(jmeterProperties);
JMeterUtils.initLogging();
JMeterUtils.initLocale();
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain(host);
httpSampler.setPort(port);
httpSampler.setPath(path);
httpSampler.setMethod("GET");
httpSampler.setName("load test");
LoopController loopController = new LoopController();
loopController.setLoops(1);
loopController.setFirst(true);
loopController.initialize();
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("Sample Thread Group");
threadGroup.setNumThreads(userCount);
threadGroup.setRampUp(1);
threadGroup.setSamplerController(loopController);
HashTree testPlanTree = new HashTree();
TestPlan testPlan = new TestPlan("load test");
testPlanTree.add(testPlan);
HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);
threadGroupHashTree.add(httpSampler);
jmeter.configure(testPlanTree);
jmeter.run();
运行此脚本后,我希望获得聚合摘要值,如平均延迟。我知道可以将摘要报告记录到csv文件中,然后通过再次阅读该文件来计算平均延迟。但我只想知道,是否有任何方法可以在不写入和读取csv文件的情况下获得聚合值?
我已经在这里引用了以下文章和几个相关问题
https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-guihttp://uttesh.blogspot.com/2015/04/jmeter-load-testing-by-code-jmeter-api.html显示器
1条答案
按热度按时间wgxvkvu91#
一种方法是创建一个自定义类,比如
ResultCollector
(在我的例子中是JmeterOutListener.java
),并从那里收集值,因为你可以访问它们。你可以在sampleOccurred
方法中做任何你想做的事情。您可以解码
ResultCollector
类并进一步查看其功能。从代码进行JMeterTest.java
JmeterOutListener.java编译器