Search code examples
jmeterperformance-testingload-testing

How to group responses in report by exceptions/assertions during JMeter test run


During the test I've got 3 types of exception from the same requests (or may be from different also).
I want to sort and to group them in any kind of view to see how many each type of exceptions are there. I can add response assertion for each type of exception in the response, but how can I group them in report? In the ideal case I would like to get:

  • DuplicateKeyException - 22% of samplers
  • NullPointerException - 5% of samplers
  • WorstEverException - 10% of samplers

Any ideas how to do that?


Solution

  • I think of at least 2 ways:

    1. Use Sample Variables property like:

      • Extract the Exception type from the response using the relevant Post-Processor and store it into a JMeter Variable called i.e. Exception
      • Add the next line to user.properties file:

        sample_variables=Exception
        
      • Next time you run your test in command-line non-GUI mode like:

        jmeter -n -t test.jmx -l result.csv
        

        you will see an extra column called Exception having the value of the exception. Now you should be able to use LibreOffice Calc or Microsoft Excel to calculate the percentages for a certain exception

    2. You can use JSR223 Listener in order to rename the sampler according to the Exception occurred, the relevant code would be something like:

      if (!prev.isSuccessful()) {
          prev.setSampleLabel((prev.getResponseDataAsString() =~ "(\\w+)Exception")[0][1] as String)
      }
      

      where prev is a shorthand for the parent SampleResult

      The above code will extract the exception type from the response (if the sampler is failed and the exception type is there) and rename the sampler according to the exception type.

      You can find more information on Groovy scripting in the Apache Groovy - Why and How You Should Use It article