jmeter测试java,使用JMeter测试Java类

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

class that implements the

JavaSamplerClient interface.

I'm not sure how to get the org.apache.jmeter.protocol.java.sampler.JavaSamplerClient Interface as there is no Maven Artifact nor provided binaries on the JMeter side.

Just a JMeter Maven Plugin (which is not what I'm looking for).

I could install the needed binaries in my local Maven Repository, I Just don't know where they are available.

Wondering if anybody at all is using the "Java Request Sampler" ?

P.S. Maybe I should try the JUnit Sampler

解决方案

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值