我必须通过Java编码生成Jmeter仪表板报告。在Java代码下面,我曾经用来生成普通的jmeter报告。我必须生成一个 通过Java的仪表板报告。
public class JMeterFromExistingJMX {
public static void main(String[] argv) throws Exception {
// JMeter Engine
StandardJMeterEngine 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();// log
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
FileInputStream in = new
FileInputStream
("/path/to/your/jmeter/extras/Test.jmx");
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();
}
}
}
答案 0 :(得分:1)
首先,您需要在生成报告信息中心之前生成一个.jtl结果文件,因此请确保将以下代码块添加到您的函数中:
^C
然后,您需要设置HTML Reporting Dashboard目标:
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);
最后,您可以像这样调用ReportGenerator类:
JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, "/where/you/want/the/dashboard/to/be/generated");
完整代码以防万一:
ReportGenerator generator = new ReportGenerator(logFile,null);
generator.generate();
参考文献: