Use ReadyAPI assertions to validate response and request contents: response codes, header values, specific fields in JSON and XML response bodies, and so on.
Validate the response content and add more specific assertions to check if the service gets and returns data in the expected format and whether it functions properly.
To learn more about available assertions and their parameters, see Assertion Reference.
Smart assertion
The easiest way of validating responses is with the Smart Assertion. It checks both the message content and the metadata such as headers, status codes, and parameters in accordance with the predefined set of rules. You can create a Smart Assertion from the Assertion panel. For REST, GraphQL, and SOAP requests, you can create it from the response editor as well:
-
After you get a response (or a request in REST VirtResponse and SOAP VirtResponse test steps), open the Assertions tab and click Smart Assertion.
-
Specify the assertion type:
-
Received Data – The assertion will verify the payload of the request or response.
-
Received Metadata – The assertion will verify the metadata of the request or response; depending on the protocol, those can include headers, the HTTP status code, or Kafka partition and key values.
Note: The Smart Assertion can verify either the data or the metadata. To assert both, add another Smart Assertion. -
-
Modify the assertion configuration, if needed.
Click Save.
-
Send a request, using the REST Request, GraphQL Query, GraphQL Mutation, or SOAP Request test step.
-
Click Smart Assertion in the Response editor.
-
Specify the assertion type:
-
Received Data – The assertion will verify the payload of the response.
-
Received Metadata – The assertion will verify the metadata of the response; depending on the protocol, those can include headers, the HTTP status code, or Kafka partition and key values.
Note: The Smart Assertion can verify either the data or the metadata. To assert both, add another Smart Assertion. -
-
Modify the assertion configuration, if needed.
Click Save.
For details about configuring the assertion, see the Smart Assertion reference.
Create assertions
-
In the Add Assertion dialog, select an assertion category, pick an assertion, and click Add. The assertion will be added to the Assertions panel.
Note: Some assertions may be missing from the dialog. It happens because they are not applicable to the currently selected test step or operation.
The Recently category of the dialog lists 5 recently used assertions. -
Configure and order your assertions in the Assertions panel.
Group assertions
You can group assertions together into logical assertion groups.
An assertion group behaves like a regular assertion: it can either pass or fail. Its status depends on statuses of assertions included in it and the logic applied: it can either pass if at least one of its assertions passes, or pass only if all its assertions pass.
An assertion group can include other assertion groups, but only one level deep. In other words, Group A can include Group B, but Group B cannot include Group C in its turn.
Tip: | Assertion groups are especially useful when testing asynchronous APIs like Kafka where one test step receives multiple messages. |
Create assertion group
To create an assertion group:
-
Open a test step in the editor and click in the Assertions panel.
Note: To create an assertion group, the test step must have at least two assertions. -
Select the logic that will decide if the assertion group passes:
-
AND – The assertion group passes if each assertion included in it passes.
-
OR – The assertion group passes if at least one assertion included in it passes.
-
-
Select assertions that will be included in the group and click Add Group:
Remove assertion group
Clone assertions
You can clone assertions and assertion groups you used in a request or response and apply them to another test step in the same or another test case or project. To do this, click on the toolbar of the Assertions panel and configure the following options as needed and apply the changes:
Option | Description |
---|---|
Assertions |
A list of available assertions to clone. |
Target Project |
A project to clone the assertion to. |
Target Test Suite |
A test suite to clone the assertion to. |
Target Test Case |
A test case to clone the assertion to. |
Target Test Steps |
A list of available test steps to clone the assertion to. |
Overwrite |
Assertions of some types can be added several times to a test step, while assertions of some other types can be added only once. The Overwrite option affects cloning of such “one-instance” assertions:
The option does not affect multiple-instance assertions: ReadyAPI always adds copies of these assertions to the assertion list. |
Clear Existing |
Removes any existing assertions with the same name. |
Open List |
Displays the list of updated test requests. |
Assertions panel
The Assertions panel lists the assertions you added to a test step or operation. Here, you can add and modify the assertions.
To access the Assertions panel:
Use the panel toolbar to manage assertions:
Command | Description | ||
---|---|---|---|
Adds a new assertion. |
|||
Configures the selected assertion. |
|||
Copies the selected assertion with all its settings and parameters to another test step in the same or another test case or project. See Clone assertions for details. |
|||
and |
Changes the position of the selected assertion in the panel.
The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed: |
||
Adds an assertion group. See Group assertions for details. |
|||
Removes the selected assertion group. See Remove assertion group for details. |
|||
Removes the selected assertion. |
Use the panel toolbar to manage assertions:
Command | Description | ||
---|---|---|---|
Adds a new assertion. |
|||
Configures the selected assertion. |
|||
and |
Changes the position of the selected assertion in the panel.
The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed: |
||
Removes the selected assertion. |
Use the panel toolbar to manage assertions:
Command | Description | ||
---|---|---|---|
Adds a new assertion. |
|||
Configures the selected assertion. |
|||
and |
Changes the position of the selected assertion in the panel.
The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed: |
||
Removes the selected assertion. |
See Also
Load Test Assertions
Security Assertions
Validating Virtual APIs