An HTTP 200 response can still contain an error page or the wrong content. A Response Assertion in Apache JMeter checks an expected part of the response and marks the sample as failed when that content is missing.

An assertion placed beneath one sampler checks that sampler's responses. An assertion under a controller or thread group can affect several samplers, so its position in the test tree matters as much as the matching rule. The Text Response field checks the body without HTTP headers.

A short GUI test makes it easier to distinguish a content failure from a connection or HTTP error. A working HTTP Request sampler and a thread group with one user and one iteration are enough to check a response value such as ready. View Results Tree shows the response and any assertion failure, but consumes too much memory for a load run.

Steps to add a response assertion in JMeter:

  1. Select the HTTP Request sampler in your open test plan.

    The sampler named GET status requests a status page that returns ready when the application is healthy.

  2. Add Response Assertion beneath the sampler from its right-click menu under Add → Assertions → Response Assertion.

    The new assertion defaults to Main sample only and Text Response, which check the main response body rather than sub-samples or headers.

  3. Select Substring under Pattern Matching Rules.

    Substring looks for literal, case-sensitive text anywhere in the body. Equals compares the whole body, while Contains and Matches use regular expressions. With Ignore Status cleared, HTTP errors still fail even if their bodies contain the expected text.

  4. Click Add below Patterns to Test.
  5. Enter ready in the new Patterns to Test row.

    The pattern must identify a successful response from your application. A JSON field is better checked with a JSON-aware assertion when formatting or whitespace can vary.
    Related: How to add a JSON assertion in JMeter

  6. Enter Response body did not contain ready in Custom failure message.
  7. Add View Results Tree beneath the sampler from Add → Listener → View Results Tree in its right-click menu.

    An existing View Results Tree listener covering this sampler is sufficient.

  8. Save the test plan with File → Save.
  9. Start the one-user test with Run → Start.

    If JMeter reports an existing results file, Append to existing file preserves its contents. GUI listeners are for debugging; load runs belong in non-GUI mode.
    Related: How to run a JMeter test from the command line

  10. Select the new sample in the results list inside View Results Tree.
  11. Select the Response data tab.
  12. Confirm that the asserted sample passes with ready in its response body.

    A green sample icon means the request and its assertions passed. A red sample can still have HTTP status 200 when the body fails the assertion. Expanding a failed sample reveals the Response Assertion result and the custom failure message.

Share this guide