gpt4 book ai didi

java - 如何从 Java 程序创建和运行 Apache JMeter 测试脚本并捕获输出?

转载 作者:行者123 更新时间:2023-11-30 10:13:10 25 4
gpt4 key购买 nike

<分区>

我是 jmeter API 世界的新手。我正在使用 API 创建基于 Java 的 jmeter 测试。我关注了线程:How to create and run Apache JMeter Test Scripts from a Java program?让请求运行。

现在,我需要解析输出。我一直在寻找使用 JSONPostProcessor 类。任何关于如何接线的建议将不胜感激。

代码看起来像这样:

import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;

public class JMeterTestFromCode {

public static void main(String[] args){
// Engine
StandardJMeterEngine jm = new StandardJMeterEngine();
// jmeter.properties
JMeterUtils.loadJMeterProperties("c:/tmp/jmeter.properties");

HashTree hashTree = new HashTree();

// HTTP Sampler
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain("www.google.com");
httpSampler.setPort(80);
httpSampler.setPath("/");
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);

// Test plan
TestPlan testPlan = new TestPlan("MY TEST PLAN");

hashTree.add("testPlan", testPlan);
hashTree.add("loopCtrl", loopCtrl);
hashTree.add("threadGroup", threadGroup);
hashTree.add("httpSampler", httpSampler);

jm.configure(hashTree);

jm.run();

//NEED HELP ON HOW TO GET RESPONSE FROM THE EXECUTED REQUEST
}
}

谢谢苏尼尔

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com