如何通过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. docker gitlab 如何git clone?2. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!3. nignx - docker内nginx 80端口被占用4. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?5. docker镜像push报错6. font-family - 我引入CSS3自定义字体没有效果?7. android - 目前有哪些用Vue.js开发移动App的方案?8. PHP中的$this代表当前的类还是方法?9. angular.js - 求一款angular插件10. css3 - css字体样式加填充色而不是背景色