如何使用Java在jmeter api中为testPlan或线程组添加所需的侦听器? [英] How to add required listeners for testPlan or thread group in jmeter api using java?

查看:202
本文介绍了如何使用Java在jmeter api中为testPlan或线程组添加所需的侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Apache Jmeter API创建了Jmeter脚本.但是,无法理解如何使用Java在jmeter api中为testPlan或线程组添加所需的侦听器?

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?

请帮帮我

推荐答案

完全没有.侦听器在您开发或调试测试时非常有用,当涉及到测试执行时,您要做的就是生成一个.jtl结果文件.

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.

侦听器不会添加任何值,当您以非GUI模式(即从Java代码)运行负载测试时,它们只会在内存使用和增加的磁盘IO方面造成资源开销.请参阅贪婪的侦听器-性能测试的内存泄漏文章更多细节.

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.

因此,无需添加侦听器,只需修改Java代码即可将存储的JMeter测试结果添加到.jtl文件中,一旦测试完成,您就可以使用所选的侦听器打开此.jtl结果文件或生成 HTML报告仪表板.

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.

如果不确定如何从Java代码生成.jtl结果文件,请参见以下代码段:

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

这篇关于如何使用Java在jmeter api中为testPlan或线程组添加所需的侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆