无法从Java代码运行jmeter

时间:2016-01-18 19:26:32

标签: jmeter

我尝试在eclipse中运行以下代码,该代码已发布here

但它没有被执行。它会引发以下错误:

  

注意:我还从jmeter安装文件中添加了外部罐子   LIB / EXT

代码:

public class JMeterFromScratch {

    public static void main(String[] args){
        // Engine
        StandardJMeterEngine jm = new StandardJMeterEngine();
        JMeterUtils.loadJMeterProperties("//Users//z001rdr//Documents//workspace//PerfTest//src//test//jmeter/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);

        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);
        jm.run();
    }
}

1 个答案:

答案 0 :(得分:0)

看起来你的Maven配置不正确

退房: