如何通过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. 面向对象编程 - java动态加载和类型转换问题?2. java - springMVC配置的controller无法返回jsp文件3. javascript - 看一些高手写代码单独用 “$”和“_” 来表示变量,什么时候单独使用这两个字符?4. python - 关于beautifulsoup获取文档内容5. MySQL 中怎么修改字段名,不更改属性?6. Python爬取网页requests乱码7. android的checkbox在xml添加和在java代码中添加样式不一样?8. 前端 - 使用vue2服务端渲染的时候,如何在服务端请求数据,然后给vue渲染9. javascript - 项目用IE浏览器打开修改前端内容,后台数据修改了,但是前端页面内容不变,用谷歌浏览器测试前端页面可以刷新,求大神解决。10. mysql - 仅仅只是把单引号与反斜杠转义不用prepare statement能否避免sql注入?
