I have 2 JSON requests in JMeter, both have similar structure, with some Response Assertions under them. These are the structures of those requests:
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:
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:
Untick "Ignore status" box everywhere, in this case any failed assertion will cause the sampler failure (remaining assertions won't be executed)
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