Varun
Varun

Reputation: 61

JMeter JavaSampler : How to invoke methods from external jars?

Just to give you a context of what i want to achieve :

My functional test team have a java library, which comprises of HTTP calls, based out of REST architecture. I basically want to re-use the jars and invoke methods at higher concurrency. I just wanted to know how this can be achieved using JMeter's JavaSampler?

Example : Lets say I want to do a 100 user login and log-out test, and my jar provides me with the login and logout functionality, then how would my test look like? Any pointers around this would be very helpful for me to get started.

Upvotes: 1

Views: 10215

Answers (4)

Kumar
Kumar

Reputation: 907

Can add the Jar file in the Test Plan

Check this link. which has step by step detail for using an external jar

Upvotes: -1

MonkeyTester
MonkeyTester

Reputation: 139

This is working for me with BeanShell post-processors (jmeter 3.2):

  1. Put your external jar files in your lib\ext folder
  2. Restart jmeter
  3. Import packages in a BeanShell script

I am then able to reference the relevant classes in my script.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168092

Option 1 - Using Groovy

  1. Add the jar(s) which implement your functionality somewhere to JMeter Classpath
  2. Restart JMeter to pick them up
  3. Add JSR223 Sampler to your Test Plan, make sure you choose groovy as a language and make sure Cache compiled script if available box is checked
  4. Put the code you want to run in parallel into "Script" area and use JMeter Thread Group to set up the concurrency.

Option 2 - Using Java Request

Create your own class implementing JavaSamplerClient interface and create your own overrides of the setupTest(), getDefaultParameters and especially runTest() methods. You can see the following existing classes for reference:


Option 3 - Using jmh

JMH stands for Java Microbenchmark Harness so if you just need to measure method execution timings you can do it even without JMeter, check out Getting Started With JMH guide for more information.

Upvotes: 3

Prakash Palnati
Prakash Palnati

Reputation: 3409

Place you jar files in the lib folder inside your jmeter folder.

restart and just try importing the corresponding classes.

Upvotes: 2

Related Questions