Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.emerge.nongui.test.LoadTestingNonGUI;
- import org.apache.jmeter.config.Argument;
- import org.apache.jmeter.control.LoopController;
- import org.apache.jmeter.engine.StandardJMeterEngine;
- import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
- import org.apache.jmeter.protocol.http.util.HTTPArgument;
- import org.apache.jmeter.testelement.TestPlan;
- import org.apache.jmeter.threads.ThreadGroup;
- import org.apache.jmeter.util.JMeterUtils;
- import org.apache.jorphan.collections.HashTree;
- import org.junit.Test;
- public class JmeterNonGuiTest {
- @Test
- public void test()
- {
- StandardJMeterEngine jmeter = new StandardJMeterEngine();
- HashTree testPlanTree = new HashTree();
- HTTPSampler httpSampler = new HTTPSampler();
- httpSampler.setProtocol("http");
- httpSampler.setDomain("hostname");
- httpSampler.setPort(8080);
- httpSampler.setPath("pathname");
- httpSampler.setMethod("POST");
- HTTPArgument httpArgument = new HTTPArgument();
- httpArgument.setValue("[{ \"firstname\": \"venkatachalam\", \"name\": \"Venkata\"}]");
- // Loop Controller
- LoopController loopController = new LoopController();
- loopController.setLoops(1);
- loopController.addTestElement(httpSampler);
- loopController.setFirst(true);
- loopController.initialize();
- // Test Plan
- TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
- // Thread Group
- ThreadGroup threadGroup = new ThreadGroup();
- threadGroup.setNumThreads(1);
- threadGroup.setRampUp(1);
- threadGroup.setSamplerController(loopController);
- // Construct Test Plan from previously initialized elements
- testPlanTree.add("testPlan", testPlan);
- testPlanTree.add("loopController", loopController);
- testPlanTree.add("threadGroup", threadGroup);
- testPlanTree.add("httpSampler", httpSampler);
- // Run Test Plan
- jmeter.configure(testPlanTree);
- jmeter.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement