如何通过Java编码生成Jmeter仪表板报告。(不是Windows或Shell命令)
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(); } } }
相关文章:
1. javascript - jQuery中live事件在移动微信端下没有效果;代码如下2. javascript - 可以DIY的页面是如何实现的?3. html5 - 用h5本地存储是否安全?4. 关于mysql unique的问题,如图所示5. python - uwsgi+django的搭建问题6. javascript - 运行vue源码的指令报错7. 网页爬虫 - Python爬虫入门知识8. android - 百度地图拖拽图标后原来位置的图标还在?9. showpassword里的this 是什么意思?代表哪个元素10. mysql怎么保存一件游戏装备,一般游戏开发是否用mysql