Shantanu Shinde
Shantanu Shinde

Reputation: 1012

JMeter check percentage assertions that are passing

JMeter has a way to generate a report on the % tests passing, using the Summary Report. But in that feature, if all other assertions in a HTTP request pass but even one fails, then the request is counted as 100% failing.

I am trying to find a way to get the percentage of the assertions that are failing. Is there any way to achieve this?

Will I have to create individual tests with single assertions for this or there is a better way to do this?

Upvotes: 0

Views: 251

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

You can calculate it using JSR223 Listener and the code like:

def passed = prev.getAssertionResults().findAll { !it.isFailure() }.size()
def failed = prev.getAssertionResults().findAll { it.isFailure() }.size()

def failedPercentage = failed * 100.0f / (passed + failed)

vars.put('failedPercentage', failedPercentage as String)

Where:

See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on these and other JMeter API shorthands available for the JSR223 Test Elements

In order to add the failed assertions percentage to the .jtl results file you can add the next line to user.properties file:

sample_variables=failedPercentage

More information: Sample Variables

Once done you can even plot the percentage of failed assertions as a custom chart in the HTML Reporting Dashboard

Upvotes: 0

Related Questions