title: How to create and run Apache JMeter Test Scripts from a Java program?
body: <p>I want to use the API provided by Apache JMeter to create and run test scripts from a Java program. I have understood the basics of ThreadGroup and Samplers. I can create those in my Java class by using the JMeter API.</p>
  
  <pre><code>ThreadGroup threadGroup = new ThreadGroup();
      LoopController lc = new LoopController();
      lc.setLoops(5);
      lc.setContinueForever(true);
      threadGroup.setSamplerController(lc);
      threadGroup.setNumThreads(5);
      threadGroup.setRampUp(1);
  
  HTTPSampler sampler = new HTTPSampler();
      sampler.setDomain("localhost");
      sampler.setPort(8080);
      sampler.setPath("/jpetstore/shop/viewCategory.shtml");
      sampler.setMethod("GET");
  
      Arguments arg = new Arguments();
      arg.addArgument("categoryId", "FISH");
  
      sampler.setArguments(arg);
  </code></pre>
  
  <p>However, I am not getting any idea on how to create a test script combining the thread group and sampler and then execute it from the same program. Any ideas? </p>