JMeter – JSR223 Assertion

JSR223 Assertion is a scripting-based assertion element of JMeter. JSR stands for Java Specification Requests. As same as BeanShell Assertion which we discussed earlier; you will need to implement the assertion logic by yourself using one of the supported scripting languages like Groovy, BeanShell, java, javascript, jexl etc. Usually, it is helpful when you need to write custom code based on some unique algorithm which is not currently provided by JMeter. You can create your own implementation of the code using JSR223 Assertion. 

How to add ‘JSR223 Assertion’?

You can follow the below steps:

  1. Select the ‘Sampler’ node whose response needs to be validated
  2. Right-click on the sampler element
  3. Hover the cursor on ‘Add’
  4. Hover the cursor on ‘Assertions
  5. Click ‘JSR223 Assertion’
JMeter - JSR223 Assertion
Figure 01: JMeter – JSR223 Assertion

What are the input fields of ‘JSR223 Assertion’?

‘JSR Assertion’ has the following input fields:

  1. Name: To provide the name of the assertion
  2. Comments: To provide arbitrary comments (if any)
  3. Language: To choose the scripting language. 
  4. Parameters: Parameters to pass to the script. This is an optional attribute.  
  5. Script file: A file containing the script to run. The return value is the desired output.
  6. Script compilation caching: Unique String across Test Plan that JMeter will use to cache the result of script compilation if the language used supports a Compilable interface (Groovy is one of these, java, BeanShell and javascript are not)
  7. Script: The manual script which contains the assertion logic.

Recommendation: 

It is recommended to use JSR223 test elements and Groovy as a language for any scripting. Groovy scripting is as fast as Java while BeanShell and JavaScript need to be interpreted, which causes some performance overhead.


You may be interested:


2 thoughts on “JMeter – JSR223 Assertion”

Leave a Comment