美文网首页
JMeter 生成 jmx 文件

JMeter 生成 jmx 文件

作者: zhanghanga | 来源:发表于2019-01-15 10:40 被阅读0次

/**

* jmx 文件生产者

* @author zhanghang

* @date 2018-12-25

*/

public class JMXCreator {

    public static void main(String[] argv) throws Exception {

        // Initialize the configuration variables

        String jmeterHome = "C:\\Users\\Wu\\Desktop\\apache-jmeter-5.0";

        JMeterUtils.setJMeterHome(jmeterHome);

        JMeterUtils.loadJMeterProperties(JMeterUtils.getJMeterBinDir() + "\\jmeter.properties");

        JMeterUtils.initLogging();

        JMeterUtils.initLocale();

        // TestPlan

        TestPlan testPlan = new TestPlan();

        testPlan.setName("Test Plan");

        testPlan.setEnabled(true);

        testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());

        testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());

        // ThreadGroup controller

        LoopController loopController = new LoopController();

        loopController.setEnabled(true);

        loopController.setLoops(5);

        loopController.setProperty(TestElement.TEST_CLASS,LoopController.class.getName());

        loopController.setProperty(TestElement.GUI_CLASS,LoopControlPanel.class.getName());

        // ThreadGroup

        ThreadGroup threadGroup = new ThreadGroup();

        threadGroup.setName("Thread Group");

        threadGroup.setEnabled(true);

        threadGroup.setSamplerController(loopController);

        threadGroup.setNumThreads(5);

        threadGroup.setRampUp(10);

        threadGroup.setProperty(TestElement.TEST_CLASS,ThreadGroup.class.getName());

        threadGroup.setProperty(TestElement.GUI_CLASS,ThreadGroupGui.class.getName());

        // HTTPSamplerProxy

        HTTPSamplerProxy httpSamplerProxy = new HTTPSamplerProxy();

        httpSamplerProxy.setProperty(TestElement.GUI_CLASS,"ThreadGroupGui");

        httpSamplerProxy.setDomain("site.baidu.com");

        // Create TestPlan hash tree

        HashTree testPlanHashTree = new HashTree();

        testPlanHashTree.add(testPlan);

        // Add ThreadGroup to TestPlan hash tree

        HashTree threadGroupHashTree = new HashTree();

        threadGroupHashTree = testPlanHashTree.add(testPlan, threadGroup);

        // Add Java Sampler to ThreadGroup hash tree

        HashTree javaSamplerHashTree = new HashTree();

        javaSamplerHashTree = threadGroupHashTree.add(httpSamplerProxy);

        // Save to jmx file

        SaveService.saveTree(testPlanHashTree, new FileOutputStream("C:\\Users\\Wu\\Desktop\\test.jmx"));

    }

}

相关文章

网友评论

      本文标题:JMeter 生成 jmx 文件

      本文链接:https://www.haomeiwen.com/subject/dlmedqtx.html