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
-
From the quick access page, click Add an assertion.
The
Add assertion page appears.
- Provide the assertion details.
-
Assertion name. Enter a name for the assertion.
-
Namespace. Specify the namespace for the assertion.
-
Version number. Provide the version number of the assertion.
-
Tags. Add relevant tags for identification.
-
Click Create.
The assertion file is created and displayed.
- 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.