In functional tests, you can apply assertions to various types of test steps. Depending on the test step type, there are different assertions available.
Prepare a test step
-
Double-click the test step in the Navigator to open its editor.
-
Run the request you are planning to assert at least once to get the response from the endpoint. To do that, click .
Note: If you want to add the assertion for the SOAP VirtResponse test step, run the request you have associated with this virtual response.
Now, you can use the response data during the assertion creation.
Create assertions from the response
Create a 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 an assertion for a specific element
You can quickly add assertions for specific elements in the response. To do that:
-
Right-click the element you want to check in the Outline panel of the response editor.
-
Select the desired assertion from the Add Assertion menu item.
There are the following options:
-
for Content – checks whether the selected element contains the specified value.
-
for Count – checks whether the selected element appears the specified number of times.
-
for Existence – checks whether the selected element exists in the response.
-
for Content matching RegEx – checks whether the selected element matches the specified regular expression.
-
for Existence with Script – checks whether the selected element exists in the response by using a Groovy script.
-
Open the Assertions panel
To open the Assertions panel, click Assertions at the bottom of the test step editor.
-
To learn how to work with the Assertions panel, see Verifying Results.
-
To learn about different assertion types, see Assertions Reference.
Group assertions
For functional tests, you can group assertions into assertion groups. Such groups behave like regular assertions and pass or fail based on the status of assertions included in them. To learn more about working with assertion groups, see Group Assertions.
Related Topics of Interest
Describes where you can find assertion coverage data and how to use it.
See Also
Functional Testing
Verifying Results
Assertion Reference
Transferring Property Values