How to write a JMeter test for Java Request

前端 未结 3 1598
不思量自难忘°
不思量自难忘° 2020-12-09 00:11

I need to do load testing on in memory databases.

I want to use JMeter and am under the impression I need to write a class that implements JavaSamplerClient.

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 00:59

    To use Java Request in JMeter you must create a Java class that inherits from JavaSamplerClient. To do that, you must download two jar files and add them to classpath if you are working with Eclipse. This two jar files are ApacheJMeter_core.jar and ApacheJMeter_java.jar An your class will look like that:

    import org.apache.jmeter.config.Arguments;
    import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
    import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
    import org.apache.jmeter.samplers.SampleResult;
    public class javaRequest extends AbstractJavaSamplerClient {
    
            @Override
            public void setupTest(JavaSamplerContext context){
            // TODO Auto-generated method stub
    
            super.setupTest(context);
            }
            @Override
            public Arguments getDefaultParameters() {
            // TODO Auto-generated method stub  
    
    
            }
            @Override
            public SampleResult runTest(JavaSamplerContext arg0) {
                // TODO Auto-generated method stub
    
                SampleResult result = new SampleResult();
    
                    boolean success = true;
    
                    result.sampleStart();
    
                    // Write your test code here.
    
                    //
    
    
                    result.sampleEnd();
    
                    result.setSuccessful(success);
    
                    return result;
    
            }
            @Override
            public void teardownTest(JavaSamplerContext context){
                // TODO Auto-generated method stub
                driver.quit();
                String verificationErrorString = verificationErrors.toString();
                if (!"".equals(verificationErrorString)) {
                    fail(verificationErrorString);
                    System.out.println(verificationErrorString); 
                }
                super.teardownTest(context);
            }
    }
    

    For more informations you can visit this link http://www.javacodegeeks.com/2012/05/apache-jmeter-load-test-whatever-you.html/comment-page-1/#comment-8288 and this page too How to use CSV Data Set with junit request test in jmeter

提交回复
热议问题