5. Add Assertions to Functional Tests

Assertions validate that your test results match the expected behavior. In ReadyAPI, use assertions to verify response codes, response headers, and individual values in response bodies, request execution time, and other checks. The test runner runs assertions after a test step (request) is over.

Example 1 – SLA Assertion

Use an SLA assertion to verify that the service responds within a defined time limit.

  1. In the Navigator, in Functional Tests, select GET Request and click Add Assertion.

    ReadyAPI interface showing a selected GET request in the Navigator and the Add Assertion button in the request editor.
  2. In the Add Assertion dialog, in Categories, select SLA, then Response SLA, and click Add Assertion.

    Add Assertion dialog in ReadyAPI showing SLA category selected, Response SLA assertion highlighted, and Add Assertion button.
  3. In the Response SLA Assertion dialog, enter the maximum response time (for example, 300 ms), and click OK.

    Note

    SLA (service-level agreement) defines the maximum acceptable response time.

    ReadyAPI applies the assertion immediately if response data is available.

  4. Open the Assertions tab to view the result:

    • If the response time is within the limit, the assertion passes.

    • If it exceeds the limit, the assertion fails.

    In this example, the assertion fails because the request was executed for a longer time than expected.

    ReadyAPI assertions panel showing a failed Response SLA assertion with error message.
  5. To increase the time limit, open Assertions, click Configure assertion RAPI_Icon_Configure_Assertion.png or double-click the assertion, update the Response SLA value, and click OK.

    Note

    ReadyAPI evaluates the assertion each time the request runs.

    Tip

    You can add Response SLA and some other assertions to requests with the New Functional Test wizard.

    ReadyAPI interface showing a failed Response SLA assertion and the dialog to update the maximum response time value.

    The Response SLA now has the PASS status.

    ReadyAPI Assertions panel showing a Response SLA assertion with PASS status.

Example 2 – Check Response Contents

Use a JSONPath assertion to validate specific values in the response body.

  1. Ensure the request returns a response. If needed, click Send to run it. For more details, see Run individual requests.

  2. In Assertions, click Add assertion .

  3. In the Add Assertion dialog, from Categories, select Property Content, then JSONPath Match, and click Add Assertion.

    ReadyAPI Add Assertion dialog showing the Property Content category with JSONPath Match selected and the Add Assertion button highlighted.
  4. In the JSONPath Match Assertion dialog, enter a JSONPath Expression that will extract some field from the response body and the expected value of this field.

    You have the following options to enter the expression:

    • Type the expression manually, or

    • Click Select node RAPI_Icon_Select_Node.png to choose a value from the response

      Important

      The Select node RAPI_Icon_Select_Node.png option works only if the request returns a response.

    For this tutorial, click Select node RAPI_Icon_Select_Node.png, select the status field, and click OK.

    ReadyAPI Select JSON dialog highlighting a selected JSON node value and OK button.

    The JSONPath Expression field now contains the selector, and the Expected Result contains the value extracted from the current response data.

    ReadyAPI dialog showing a JSONPath Match assertion with the expression .status and expected result set to available.
  5. Click Save and view the result in the Assertions panel.

    • The assertion passes if the value matches.

    • The assertion fails if the value changes.

    ReadyAPI interface showing passed assertions including JSONPath Match and Response SLA.

PrevNext

See Also

Publication date: