Skip to content

JMeter Assertion Failed

Fix JMeter assertion failures: Response Assertion text expected to contain, JSON Assertion path mismatches, Duration and Size assertions. Causes and fixes.

Difficulty
intermediate
Guide type
troubleshooting
Estimated read time
6 min read
Last verified version
Verified JMeter 5.6

Samplers are marked failed even though the server answered, with messages such as:

  • Test failed: text expected to contain /expected text/
  • Assertion failure message: ... in the JTL or View Results Tree
  • Test failed: path expected to exist, but was not found (JSON Assertion)
  • Duration Assertion / Size Assertion failures under load

The response code is usually 200 โ€” the sampler fails because the body, duration, or size did not match what the assertion expects.

The response you asserted on is not the response you got. Either the application returned different content (dynamic values, an error page with status 200), or the assertion itself is too strict โ€” wrong pattern mode, wrong scope, or an un-correlated variable.

CauseDetail
Dynamic or localized contentSession IDs, timestamps, tokens, or personalized text baked into the assertion
Wrong pattern-matching modeMatches (full regex) or Equals used where Contains / Substring was intended
Wrong assertion scopeAssertion applied to sub-samples (redirects, embedded resources) or to the wrong field (headers vs body)
Failed upstream correlation${var} resolves to a literal or default, so the asserted text never existed โ€” see extractor default value and 401/403 after recording
JSON path returns an arrayJSON Assertion path matches [] or multiple nodes where a scalar was expected
Whitespace / encoding differencesPretty-printed JSON, CRLF, or HTML entities differ from the recorded expectation
Server returned an error page with 200The body contains an error message while the status stays green
Negative assertions invertedNot checkbox or Contains on a value that legitimately appears
  1. Read the Assertion failure message in View Results Tree โ€” it states which assertion failed and what was expected vs received. In CLI runs, set jmeter.save.saveservice.assertion_results_failure_message=true so JTL rows carry the message.
  2. Reproduce once in GUI mode with 1 thread and compare the actual response body against the asserted pattern.
  3. Check the assertionโ€™s scope: โ€œMain sample onlyโ€ vs โ€œSub-samplesโ€, and the field being asserted (Body, Response Headers, URL Sampled).
  4. Prefer Contains or Substring pattern matching over Equals or Matches on Response Assertion; if you must use regex, escape variables with ${__escapeHtml(...)} or \Q...\E.
  5. For JSON Assertion, verify the path with a JSON Path evaluator, check Additionally assert value with a tolerant match, or tick Expect null when absence is the expected outcome.
  6. Add a Debug Sampler or Debug PostProcessor to confirm the variable the assertion references actually resolved.
  7. Re-run correlation for any recorded token; a stale CSRF or session token often surfaces first as an assertion failure on the login page.
  8. If the server returns an error page with HTTP 200, assert on a success marker instead of the status code โ€” see non HTTP response code for the inverse case.
  9. For Duration Assertion and Size Assertion failures, check whether they only trigger under load โ€” that points at server capacity, not script logic (throughput stuck).
ResourceUse when
Assertions & SLA validation guideChoosing the right assertion type and placement
Response Assertion referenceFull field-by-field documentation
JSON Assertion referenceJSON path expressions and operators
Correlation & dynamic valuesAssertion fails because a variable never resolved
Regex extractor builderTesting patterns against real response bodies

Why does my assertion pass in the browser but fail in JMeter?

Section titled โ€œWhy does my assertion pass in the browser but fail in JMeter?โ€

JMeter does not run JavaScript or render the page, and it may receive a different body than the browser โ€” often because a token or cookie was not correlated. Compare JMeterโ€™s recorded response with the browserโ€™s actual response body, not the rendered page.

How do I see assertion failure details in CLI (non-GUI) mode?

Section titled โ€œHow do I see assertion failure details in CLI (non-GUI) mode?โ€

Set jmeter.save.saveservice.assertion_results_failure_message=true in user.properties so the JTL includes the failure message, then inspect the failing rows. The HTML dashboard also surfaces assertion failures per sampler.

Almost never. Assert on a stable marker (a fixed string, JSON field, or status) with Contains or Substring matching. Exact-match assertions break on every dynamic value, timestamp, and whitespace change.

On this page