我创建了简单的JMeter测试,我不知道如何生成并保存某种JMeter报告(摘要报告,查看表e.t.c中的结果)到某个文件。
我的代码如下所示: 公共类JMeterTest扩展了BaseScenario {
protected void scenario() throws Exception {
// Engine
StandardJMeterEngine jm = new StandardJMeterEngine();
// jmeter.properties
JMeterUtils.loadJMeterProperties("D:/Java Tools/JMeter/apache-jmeter-2.11/apache-jmeter-2.11/bin/jmeter.properties");
HashTree hashTree = new HashTree();
// HTTP Sampler
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain("192.168.67.98");
httpSampler.setPort(8080);
httpSampler.setPath("/gks-server");
httpSampler.setMethod("GET");
// Loop Controller
TestElement loopCtrl = new LoopController();
((LoopController)loopCtrl).setLoops(1);
((LoopController)loopCtrl).addTestElement(httpSampler);
((LoopController)loopCtrl).setFirst(true);
// Thread Group
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(1);
threadGroup.setRampUp(1);
threadGroup.setSamplerController((LoopController)loopCtrl);
TestPlan testPlan = new TestPlan("MY TEST PLAN");
testPlan.setTestPlanClasspath("D:/JMeterTestPlan/test.jmx");
hashTree.add("testPlan", testPlan);
hashTree.add("loopCtrl", loopCtrl);
hashTree.add("threadGroup", threadGroup);
hashTree.add("httpSampler", httpSampler);
jm.configure(hashTree);
//Run TEST
jm.run();
}
}
请帮助我! 最诚挚的问候!
答案 0 :(得分:0)
在jm.run()
声明之前添加以下几行:
Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");//$NON-NLS-1$
if (summariserName.length() > 0) {
summer = new Summariser(summariserName);
}
String logFile = "/path/to/output/file.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
hashTree.add(hashTree.getArray()[0], logger);
所有输出都将以CSV格式转到/path/to/output/file.jtl
。您可以查看JMeter安装的/ bin文件夹中的jmeter.properties
文件,以确定哪些"有趣的"值是必需的并适当地覆盖它们。
可用选项包括:
jmeter.save.saveservice.output_format=csv
jmeter.save.saveservice.assertion_results_failure_message=false
jmeter.save.saveservice.assertion_results=none
jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
jmeter.save.saveservice.response_data=false
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
jmeter.save.saveservice.samplerData=false
jmeter.save.saveservice.responseHeaders=false
jmeter.save.saveservice.requestHeaders=false
jmeter.save.saveservice.encoding=false
jmeter.save.saveservice.bytes=true
jmeter.save.saveservice.url=false
jmeter.save.saveservice.filename=false
jmeter.save.saveservice.hostname=false
jmeter.save.saveservice.thread_counts=false
jmeter.save.saveservice.sample_count=false
jmeter.save.saveservice.idle_time=false
jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
jmeter.save.saveservice.default_delimiter=,
jmeter.save.saveservice.default_delimiter=\t
jmeter.save.saveservice.print_field_names=false
jmeter.save.saveservice.xml_pi=<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_21.xsl"?>
jmeter.save.saveservice.base_prefix=~/
jmeter.save.saveservice.autoflush=false
有关如何从Java代码运行JMeter测试的详细信息,请参阅5 Ways To Launch a JMeter Test without Using the JMeter GUI指南。
答案 1 :(得分:0)
当文件小于100MB时,此报告很好,较大的文件需要花费大量时间进行处理,或者它们不会被xpath处理。
更好的解决方案是使用jtl文件和CMDRunner.ext来创建不同的文件。
使用此功能,您可以使用cmdrunner轻松为特定服务创建不同的图形: http://performancewebautoamtionother.blogspot.si/2015/12/jmeter-create-graphs-with-cmdrunner.html