您的位置:首页技术文章
文章详情页

如何通过Java编码生成Jmeter仪表板报告。(不是Windows或Shell命令)

【字号: 日期:2024-04-22 18:56:49浏览:46作者:猪猪
如何解决如何通过Java编码生成Jmeter仪表板报告。(不是Windows或Shell命令)?首先,您需要在生成报告仪表板之前生成一个.jtl结果文件,因此请确保将以下代码块添加到您的函数中:

Summariser summer = null; String summariserName = JMeterUtils.getPropDefault('summariser.name', 'summary'); if (summariserName.length() > 0) {summer = new Summariser(summariserName); } String logFile = '/path/to/result.jtl'; ResultCollector logger = new ResultCollector(summer); logger.setFilename(logFile); testPlanTree.add(testPlanTree.getArray()[0], logger);然后,您需要设置HTML Reporting Dashboard目标:

JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, '/where/you/want/the/dashboard/to/be/generated');最后,您可以像这样调用ReportGenerator类:

ReportGenerator generator = new ReportGenerator(logFile,null); generator.generate();

完整的代码,以防万一:

import org.apache.jmeter.engine.StandardJMeterEngine; import org.apache.jmeter.report.dashboard.ReportGenerator; import org.apache.jmeter.reporters.ResultCollector; import org.apache.jmeter.reporters.Summariser; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.collections.hashtree; import java.io.File; import static org.apache.jmeter.JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY; public class RunJMeterTest {public static void main(String[] args) throws Exception { StandardJMeterEngine jmeter = new StandardJMeterEngine(); JMeterUtils.loadJMeterProperties('/path/to/your/jmeter/bin/jmeter.properties'); JMeterUtils.setJMeterHome('/path/to/your/jmeter'); JMeterUtils.initLocale(); SaveService.loadProperties(); hashtree testPlanTree = SaveService.loadTree(new File('/path/to/your/jmeter/bin/test.jmx')); Summariser summer = null; String summariserName = JMeterUtils.getPropDefault('summariser.name', 'summary'); if (summariserName.length() > 0) {summer = new Summariser(summariserName); } String logFile = '/path/to/your/jmeter/bin/result.jtl'; ResultCollector logger = new ResultCollector(summer); logger.setFilename(logFile); testPlanTree.add(testPlanTree.getArray()[0], logger); jmeter.configure(testPlanTree); jmeter.run(); JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, '/path/to/dashboard'); ReportGenerator generator = new ReportGenerator(logFile, null); generator.generate();} }

参考文献:

生成报告仪表板在不使用JMeter GUI的情况下启动JMeter测试的五种方法解决方法

我必须通过Java编码生成Jmeter仪表板报告。在Java代码下面,我曾用来生成普通的jmeter报告。我必须通过Java生成仪表板报告。

public class JMeterFromExistingJMX { public static void main(String[] argv) throws Exception {// JMeter EngineStandardJMeterEngine jmeter = new StandardJMeterEngine();// Initialize Properties,logging,locale,etc.// JMeterUtils.loadJMeterProperties('/path/to/your/jmeter/bin/jmeter.properties');JMeterUtils.setJMeterHome('/path/to/your/jmeter');JMeterUtils.initLogging();// logJMeterUtils.initLocale();// Initialize JMeter SaveServiceSaveService.loadProperties();// Load existing .jmx Test PlanFileInputStream in = new FileInputStream ('/path/to/your/jmeter/extras/Test.jmx');HashTree testPlanTree = SaveService.loadTree(in);in.close();// Run JMeter Testjmeter.configure(testPlanTree);jmeter.run(); } } }

标签: java
相关文章: