问题
I have created the Jmeter script from Apache Jmeter API. But, not able to understand how to add required listeners for testPlan or thread group in jmeter api using java?
Please help me out
回答1:
Simply don't. Listeners are useful when you develop or debug your test, when it comes to test execution all you need to do is to generate a .jtl results file.
Listeners don't add any value, when you run your load test in non-GUI mode (i.e. from Java code) they just create resource overhead in terms of memory usage and increased disk IO. See Greedy Listeners - Memory Leeches of Performance Testing article for more details.
So instead of adding listeners just amend your Java code to add storing JMeter test results into a .jtl file and once your test finishes you will be able to open this .jtl results file with the listener of your choice or generate HTML Reporting Dashboard from it.
If you are uncertain regarding how to generate a .jtl results file from Java code here is a snippet:
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
String logFile = "/path/to/test/result.jtl"
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(testPlanTree.getArray()[0], logger);
If you need to amend result file configuration to store some extra data or don't store metrics you don't want - you can do it via relevant JMeter Properties
来源:https://stackoverflow.com/questions/49399887/how-to-add-required-listeners-for-testplan-or-thread-group-in-jmeter-api-using-j