Monday, September 14, 2009

Writing JMeter tests using JavaRequest

JMeter supports performance testing of services that have clients written in Java using Java Request. Here are the steps needed to write a simple performance test client with that support.

1. import the necessary classes

import org.apache.jmeter.* ...

2. Create a class that implements JavaSamplerClient. Ex: JavaTester

3. Override the life cycle methods setupTest, teardownTest, runTest, getDefaultParameters

4. In the method runTest create an object of the typw SampleResult and flag the test as successful or failed based upon the response from the server.

5. Place the files ApacheJMeter_core.jar and ApacheJMeter_java.jar in classpath and compile the class JavaTester and make a jar out of it. jar -cvf JavaTester.jar JavaTester*

6.Place any additional jar files required in lib/ext directory

7. Restart JMeter, create a thread group and add a Sampler of the type Java Request. Observe that the Classname combo box should display the compiled java file, JavaTeser.

You are good to go. This is how the class looks like

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.SampleResult;

public class JavaTester implements JavaSamplerClient {

  public void setupTest(JavaSamplerContext context) {
  public void teardownTest(JavaSamplerContext context) {
  public SampleResult runTest(JavaSamplerContext context0) {
    SampleResult results = new SampleResult();

        //put code here that sends the  request to the server

     }catch(Exception exc){
     return results;
  public Arguments getDefaultParameters() {
    Arguments params = new Arguments();
    return params;



  1. hello ,

    I am trying to record the https request through proxy with jmeter 2.7 version,
    say, jmeter does not record any action log in , check check box mail button , delete the mail and log out. please provide the solution for this problem.
    Pls help me.

    Thanks in advance.

    with regards

  2. I really like this blog, It's always nice when you can not only be informed, but also get knowledge, from these type of blog, nice entry. Thanks
    performance engineering