Adding assertions

About this task

You can use assertions to specify validation criteria for test responses. Assertions compare actual API responses against expected values to verify correctness. When a test runs, the system evaluates each assertion and determines if the response meets the expected conditions. If an assertion fails, the test result highlights the discrepancy, helping you identify potential issues in the API's behavior.

Procedure

  1. From the quick access page, click Add an assertion.
    The Add assertion page appears.
  2. Provide the assertion details.
    1. Assertion name. Enter a name for the assertion.
    2. Namespace. Specify the namespace for the assertion.
    3. Version number. Provide the version number of the assertion.
    4. Tags. Add relevant tags for identification.
    5. Click Create.
    The assertion file is created and displayed.
  3. Add the assertion details.
    • Name. Enter a name for the assertion.
    • Key. Identifies the attribute of the response to validate. Use identifiers like header(), json(), xml(), or text() to differentiate content types. For example, header().Content-Type.
    • Action. Select the validation action or condition. Available options are equals, notEquals, haveProperty, notHaveProperty, lessThan, and greaterThan.
    • Value. Sets the target value against which the response attribute must be validated.
    When you define and apply assertions in tests, API Studio evaluates each condition during the test run. If an assertion passes, the response meets expectations. If an assertion fails, the system highlights the mismatch, allowing you to troubleshoot issues effectively.