When creating an API test, it is important to add assertions on the response of individual API requests to validate that the API returns the expected result. For example, you may want to assert that the status code of the request equals 200 and that the response body (JSON) contains a user with a specific email address.
Default status assertion
By default, when you create a new API step in your test, mabl will automatically create an assertion that expects the status code to be equal to 200. This assertion can be edited or removed as needed.
You can easily create assertions based on the following response data:
- Status code
Supported assertion types are:
- Does not equal
- Does not contain
- Is present
To create an assertion, take the following steps:
- In the Validation and variable assignment section, click on the Assertions tab.
- Click on the Add button. An assertion card will appear.
- Enter a description for your assertion.
- Select an assertion target. If you select Header, enter the header key. For a JSON body, type the JSON body path to the target response property.
- Select an assertion type and specify the expected value.
Response body validation
To test out your assertions, click on the Send button. In the Results section, click on the Assertions tab to check whether the assertion passed.
To edit an existing assertion, take the following steps:
- Open the Assertions tab in the Validation and variable assignment panel.
- Click on the pencil icon next to the assertion.
- Make updates to the assertion as needed.
- Click Save to confirm the updates to the assertion.
Updated 3 months ago