1
votes

My JMeter test plan looks like this:

HTTP Request
- Assertion
HTTP Request
- Assertion
HTTP Request
- Assertion
Assertion Result Listener

I'd like to define all assertion results from the listener as a variable and use that variable in a POST call to JIRA, so the description contains an overview of all assertions and failure and pass of each assertion.

Assertion Result Listener

I know I can save the assertion results to a file and upload that, but I need the assertion results as text in the JIRA. Any ideas how I can do that?

edit: this is for a functional test suite.

1

1 Answers

2
votes
  1. Add JSR223 Listener to your Thread Group
  2. Put the following code into "Script" area

    def result = vars.get('result')
    StringBuilder builder = new StringBuilder()
    if (result != null) {
        builder.append(result).append(System.getProperty('line.separator'))
    }
    
    
    prev.getAssertionResults().each { assertionResult ->
        builder.append(prev.getSampleLabel()).append(System.getProperty('line.separator'))
        if (assertionResult.isFailure()) {
            builder.append('\t').append(assertionResult.getFailureMessage()).append(System.getProperty('line.separator'))
        }
    }
    vars.put('result', builder.toString())
    props.put('result', builder.toString())
    
  3. Add tearDown Thread Group to your Test Plan

  4. Refer the generated string holding the assertion results using __P() function as ${__P(result,)}

Demo:

JMeter Assertion Results into Variable

See Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.