Verifying Results

Applies to ReadyAPI 3.54, last modified on September 23, 2024

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:

Adding validation of REST, GraphQL, and SOAP responses

Click the image to enlarge it.

  1. After you get a response (or a request in REST VirtResponse and SOAP VirtResponse test steps), open the Assertions tab and click Smart Assertion.

  2. 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.
  3. Modify the assertion configuration, if needed.

    Click Save.

Adding validation of REST, GraphQL, and SOAP responses

Click the image to enlarge it.

  1. Send a request, using the REST Request, GraphQL Query, GraphQL Mutation, or SOAP Request test step.

  2. Click Smart Assertion in the Response editor.

  3. 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.
  4. Modify the assertion configuration, if needed.

    Click Save.

For details about configuring the assertion, see the Smart Assertion reference.

Create assertions

  1. Open a test step in the editor and click Add Assertion.

    Functional tests: The Add Assertion button

    Click the image to enlarge it.

  1. Open a security test, click Response Assertions next to a security scan, and click Add in the Assertions panel.

    Security tests: The Assertions panel

    Click the image to enlarge it.

  1. Expand the Assertions drop-down menu on the right of the virtual service editor and click Add.

    APIs (Virtual): The Assertions panel

    Click the image to enlarge it.

  1. 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.
  2. 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:

  1. 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.
  2. 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.

  3. Select assertions that will be included in the group and click Add Group:

    Functional tests: Add assertion group

    Click the image to enlarge it.

Remove assertion group

To remove an assertion group, select it in the Assertions panel and click :

Remove assertion group

Click the image to enlarge it.

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 Clone on the toolbar of the Assertions panel and configure the following options as needed and apply the changes:

ReadyAPI: The Clone Assertions dialog

Click the image to enlarge it.

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:

  • If the option is on, clones will replace such assertions in the target test steps.

  • If the option is off, clones will not replace the existing 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:

Functional tests: The Assertions panel

Click the image to enlarge it.

Use the panel toolbar to manage assertions:

Command Description
Add

Adds a new assertion.

Add

Configures the selected assertion.

Clone

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.

Up and Down

Changes the position of the selected assertion in the panel.

The assertion order is important. ReadyAPI runs assertions in the order you have specified, from the topmost to the bottom one.

The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed:

ReadyAPI: The Assertions panel

Click the image to enlarge it.

Add Group

Adds an assertion group. See Group assertions for details.

Remove Group

Removes the selected assertion group. See Remove assertion group for details.

Remove

Removes the selected assertion.

Security tests: The Assertions panel

Click the image to enlarge it.

Use the panel toolbar to manage assertions:

Command Description
Add

Adds a new assertion.

Add

Configures the selected assertion.

Up and Down

Changes the position of the selected assertion in the panel.

The assertion order is important. ReadyAPI runs assertions in the order you have specified, from the topmost to the bottom one.

The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed:

ReadyAPI: The Assertions panel

Click the image to enlarge it.

Remove

Removes the selected assertion.

APIs (Virtual): The Assertions panel

Click the image to enlarge it.

Use the panel toolbar to manage assertions:

Command Description
Add

Adds a new assertion.

Add

Configures the selected assertion.

Up and Down

Changes the position of the selected assertion in the panel.

The assertion order is important. ReadyAPI runs assertions in the order you have specified, from the topmost to the bottom one.

The image below shows three assertions applied to a SOAP request test step. The first two passed correctly, and the last one failed:

ReadyAPI: The Assertions panel

Click the image to enlarge it.

Remove

Removes the selected assertion.

See Also

Load Test Assertions
Security Assertions
Validating Virtual APIs

Watch the video
 
Highlight search results