Skip to content
  • ZipCode Api
  • Blog
  • About RedLine13
RedLine13
RedLine13
Primary Navigation Menu
Menu
  • Start Testing
  • Demo
  • Pricing
  • JMeter
  • Partners
  • Docs
    • Documentation Home
    • AWS Set Up for load testing
    • AWS Approval for Large Tests
    • PHP, NodeJS, Python Load Tests
    • Scalability
    • Jenkins Plugin Setup
    • Premium Features
    • Knowledge Base

Beanshell for JMeter Best Practices

By: RedLine13

Disclaimer: This post is for those still using Beanshell. However, you should know that the Philippe Mouawad, JMeter contributor, has asked us to pass on that everyone should “avoid Beanshell in favor of JSR223 + Groovy because Beanshell is old, slow and does not support Java 5 and upper syntax.” If you still will be using Beanshell for whatever reason, here are Beanshell for JMeter Best Practices.

JMeter has powerful abilities to perform general tasks out of the box. In many performance test cases you don’t need to write code when creating test cases. However, in some circumstances you might need to write a script. At this point Beanshell comes to our aid. This post will look at Beanshell for JMeter Best Practices.

BeanShell is a light-weight scripting programming language. It has syntax similar to Java. Instead of compiling, it is an interpreted scripting language.

There are a few places you can utilize Beanshell within JMeter:

  1. BeanShell Sampler allows you to use the BeanShell scripting language to do performance tasks and measure results. Apache JMeter BeanShell Sampler Docs
  2. BeanShell Listener allows the use of BeanShell for processing samples for saving, so you can listen to results from other samples and process the response. BeanShell Listener docs
  3. BeanShell Assertion enables assertion checking with a BeanShell script, so you can check your results and use them to validate a response. BeanShell Assertion Docs
  4. BeanShell Timer can be used to generate custom delay logic. Docs
  5. BeanShell PreProcessor allows running a script before a sampler is executed. Docs
  6. BeanShell PostProcessor runs a script after a sampler is executed. Docs

Before we start to review best practices keep in mind that your first priority should be avoid scripting if possible.

Beanshell for JMeter Best Practices

Using the right syntax

BeanShell interprets standard Java statements, expressions and syntax. So it is important not to forget the basic expressions. For example:

After an expression, you must use a semicolon or once using if statement use == operator for comparison

Beanshell for JMeter Best Practices - Syntax

Using Exception Handling (try-catch)

Exception handling is a mechanism which allows exceptions to be thrown and caught. It is a very good habit to use exception handling to avoid getting errors. For example below we declared one integer variable and try to divide it by zero. Once we run the test, we will get an error and the code is terminated .

Beanshell for JMeter Best Practices - Exception Handling

However once we wrap our code within the try-catch block, our code will not be terminated and we won’t come across an error. Our test will not be affected by this error.

Check the variables value before manipulating it

This is also a common issue in JMeter trying to manipulate variables with null value. In order to avoid getting errors, it is best practice to check if the variable is a null value.

Beanshell for JMeter Best Practices - Check Variables

Using Log Viewer and log function

It is good practice to follow the logs of your test execution. To open this click Options->Log Viewer Menu tab.

Also adding extra logging like log.info (“log”); so you are able to determine which lines are fine and where execution stops by looking into Log Viewer tab or jmeter.log file

What other Beanshell for JMeter Best Practices do you follow?

Want to try this on RedLine13 but you’re new to RedLine13? This guide and video walks you through running your first JMeter test on Redline13.

2020-02-20
Previous Post: AWS Costs and Continuous Load Testing Costs
Next Post: AWS Data Costs for Load Testing

Recent Posts

  • Order of Elements in JMeter
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener
  • Using Test Fragments in JMeter Tests

Related

  • Order of Elements in JMeter
  • SAML Configuration with Azure AD and RedLine13
  • SAML Configuration with OKTA and RedLine13
  • SAML Configuration with Google and RedLine13
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener
  • Using Test Fragments in JMeter Tests
  • Step-by-Step Guide to Testing with JMeter
  • Functional Testing vs Performance Testing

© RedLine13, LLC | Privacy Policy | Contract
Contact Us: info@redline13.com

Designed using Responsive Brix. Powered by WordPress.