Home > Software design >  Inconsistent behaviour with Response Assertions in JMeter
Inconsistent behaviour with Response Assertions in JMeter

Time:06-13

I have 2 JSON requests in JMeter, both have similar structure, with some Response Assertions under them. These are the structures of those requests:

enter image description here

enter image description here

But when I run the requests, for the first one, the request is shown as passed, even when all the assertions are failing, while for the second, the entire request fails if even one assertion fails:

enter image description here

enter image description here

I expect the second behaviour, but don't understand why the same is not happening in the first. Is there any way to fix this and get the same behaviour? What could be going wrong here? Or is this some bug?

CodePudding user response:

What do you mean by inconsistent? Any chance you have Ignore Status box checked? Because if you do, then according to JMeter Documentation

When the Ignore Status checkbox is selected, the Response status is forced to successful before evaluating the Assertion

it means that each Assertion artificially treats the SampleResult as successful before evaluating even if the previous assertions have failed.

That's why given the last assertion success the sampler will be marked as successful.

There are 2 possible options:

  1. Untick "Ignore status" box everywhere, in this case any failed assertion will cause the sampler failure (remaining assertions won't be executed)

  2. Or add another JSR223 Assertion to explicitly set the SampleResult to failed if any assertion fails. Example code:

    prev.getAssertionResults().each { if (it.isFailure()) { prev.setSuccessful(false) } }
    

    More information: Scripting JMeter Assertions in Groovy - A Tutorial

  • Related