JMeter 生成 jmx 文件

/**

* 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"));


    }

}

猜你喜欢

转载自blog.csdn.net/weixin_33772645/article/details/87196179
JMX
今日推荐