Skip to content
Advertisement

Creating a New JMeter Test Purely in Java for Java Sampler

I’ve created a JMeter Java request and copied the jar to ext directory (apache-jmeter-3.1libext). I’m trying to run the test on a remote machine. From the GUI I’m able to configure and run the Java request. Also able to invoke the test via Java code using the JMX file as below.

JavaScript

Now I want to creating a New JMeter Test Purely in Java. But I don’t know how to configure the Java sampler. I see example here pointing how to configure the HTTP Sampler. Instead of HTTPSampler, I need to configure my Java Request. Please assist.

Advertisement

Answer

Example code to add a Java Request sampler which will execute SleepTest will look like:

JavaScript

In case if you need execute your own class implementing JavaSamplerClient interface just substitute the classname and provide your own arguments if needed.

Full code just in case:

JavaScript

See Five Ways To Launch a JMeter Test without Using the JMeter GUI for comprehensive information on different ways of running a JMeter test.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement