How to add required listeners for testPlan or thread group in jmeter api using java?

北战南征 提交于 2020-01-06 06:44:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!