Search code examples
automationjmeterassertions

JMeter - save assertion results as a variable


In JMeter I have an automation test plan with several assertions. In my assertion result listener I can see the result off all assertions in a handy overview. So far so good.

At the end of the test plan, I'm calling JIRA to post a new issue with the test results. I want the description of that issue to contain the overview from the assertion result listener.

How can I define the assertion results as a variable, so that I can reference them later in my JIRA call?

How can I map this view to a variable?

My JIRA call should look like this:

POST /rest/api/2/issue

{
"fields": {
   "project":
   {
      "key": "Blah"
   },
   "assignee": {
      "name": "Joe"
    },
    "priority": {
      "name": "Major"
    },
   "summary": "Jmeter Test Result",
   "description": "${assertionresults}",
   "issuetype": {
      "name": "Test Execution"
   }
}

Solution

  • You can add after the Sampler with the assertion:

    Test Action and inside it a JSR223 PreProcessor and write the following code using AssertionResult.getFailureMessage method:

      vars.put("assertionresults", prev.getAssertionResults()[0].getFailureMessage());
    

    It will save in assertionresults variable the first assertion message.