Testing Java Classes with JMeter

后端 未结 1 2033
故里飘歌
故里飘歌 2020-12-15 06:43

I\'d like to test a Java Service Call. My first attempt was to use the \"Java Request Sampler\" The docu says

This sampler lets you control a java

相关标签:
1条回答
  • 2020-12-15 07:27

    We are building with ANT and are using the JARs, which are located in the binary file from JMeter under \lib\ext\. The AbstractJavaSamplerClient which is used for the Java Request Sampler is located in the file \lib\ext\ApacheJMeter_java.jar. For working with this abstract class, you also have to import the JAR file \lib\ext\ApacheJMeter_core.jar, which is (for example) holding the class SampleResult.

    After building our Java class we put the resulting JAR file also in the folder \lib\ext\. If our class uses any dependency (3rd part JAR), we put it in '\lib' folder. After that, you can start JMeter and you're able to select your Java class in a Java Request Sampler.

    Here is an example of such a Java Request Sampler:

    public class JavaRequestSamplerDemo extends AbstractJavaSamplerClient {
    
      @Override
      public SampleResult runTest(JavaSamplerContext ctx) {
        JMeterVariables vars = JMeterContextService.getContext().getVariables();
        vars.put("demo", "demoVariableContent");
    
        SampleResult sampleResult = new SampleResult();
        sampleResult.setSuccessful(true);
        sampleResult.setResponseCodeOK();
        sampleResult.setResponseMessageOK();
        return sampleResult;
      }  
    }
    
    0 讨论(0)
提交回复
热议问题