3

I'm facing with problem don't know how to create one Java function and call it to use anywhere because I don't want to write this function many times. Could anyone give me the best solution to do it?

Sidara KEO
  • 1,693
  • 1
  • 14
  • 34

1 Answers1

0

If you still want to proceed with Beanshell (however since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language) - take a look at Beanshell configuration, there are properties like:

  • beanshell.init.file
  • beanshell.sampler.init
  • etc.

where you can place the "common" code which can be reused in the Beanshell test elements.


For Groovy as of JMeter 5.2.1 there are no equivalent properties, however you should be able to compile your Groovy code into a .jar file, put the file into JMeter Classpath and invoke the functions defined in the .jar from any JSR223 Test element. Check out How to Reuse Your JMeter Code with JAR Files and Save Time article for more details.

This approach can be applied to Beanshell as well if you still want to use it and find the properties not very convenient.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133