Applies to ReadyAPI 3.0, last modified on November 12, 2019

Why Assertions?

In ServiceV, virtual APIs (virtual services) validate incoming requests with assertions, that is, they use assertions to check the input data. This helps you verify that the client code calls the API in an expected way. Of course, the server code that implements an operation should check the input data and should return an error, if this data is invalid. However, in many cases, you can use an assertion as an additional quick check for this or that case.

Service- and Operation-Level Assertions

You can apply assertions to individual operations or to the entire virtual service:

Service virtualization and API testing: Operation assertions
Service virtualization and API testing: Virtual service assertions

Operation assertions are applied to incoming requests of the appropriate operations. Service assertions work for any incoming request.

Note: Neither operation assertions, nor service assertions work for operations that have no virtual responses defined. If you simulate such an operation, the virtual service will report the 500 Internal Server Error code, but the assertion will not fail.

Note: If needed, you can create several assertions for a virtual service or an operation. ReadyAPI will execute them in their order on the Assertions list.

How to Create an Assertion

To create a service-level assertion:
  1. Select your virtual service in the Navigator panel.

  2. Switch to the editor on the right, and, in Assertions, click .

  3. Select the assertion type and configure assertion properties in the subsequent dialogs:

    Service virtualization and API testing: Validating virtual services with assertions

    Click the image to enlarge it.

To create an operation assertion:
  1. In the virtual service editor, switch to the Setup page and select the needed operation.

  2. Switch to the editor on the right, and, in Assertions, click .

  3. Select the assertion type and configure assertion properties in the subsequent dialogs:

    Service virtualization and API testing: Validating operations with assertions

    Click the image to enlarge it.

Preparing Sample Data

The Assertion Properties dialogs have special toolbar commands and options that simplify creating verification conditions. For instance, many property dialogs have a button for testing the assertion or for easier extracting of request data.

These commands and options need sample data for their work. To provide this data, you need to send a request to the virtual service:

  1. Run your virtual service.

  2. Simulate the needed request to your service. To do this, you can use your client code, browser, or you can send a request from SoapUI tests or from the Projects page.

Available Assertions

Select the needed assertions in the Add Assertion dialog. Some of the assertions are not present there, because they cannot be applied to incoming requests: some of them are not applicable to virtual APIs, the others cannot be used with incoming request data.

For information on available assertions and their properties, see Available Assertions.

Note: There is no assertion that checks URL parameters. To verify them, use the Script assertion.

Viewing Assertion Results

Virtual services post information on assertions to the Transaction Log. To view assertion results:

  1. In the service editor, switch to the Transaction Log page.

    The log marks failed operations with a red dot (see the image below).

  2. Click a failed operation and look at the editor on the right.

    Here, in the Assertions section, you can see which assertions failed and the cause of the fail:

    Service virtualization and API testing: Assertions in the Transaction log

    Click the image to enlarge it.

Tips

  • ReadyAPI executes assertions in their order on the Assertions list. To change an assertion position, select the assertion on the list and click or .

  • To exclude an assertion from the check, right-click this assertion on the Assertions list and select Disable from the context menu. To turn on a disabled assertion, right-click it and choose Enable from the context menu.

  • To copy an assertion quickly, right-click within the Assertion list and select Clone from the context menu.

  • To verify URL parameters of a request, use the Script assertion. To get a parameter, you can parse the raw request data. See the example below.

    Show Example

  • Each assertion has a name and type name. By default, they coincide – you can see this on the Assertion list:

    Service virtualization and API testing: Assertion names and types

    If you use several assertions of the same type, you may want to assign different names to them. To do this, right-click an assertion on the list and select Rename from the context menu.

See Also

Validating Virtual APIs

Highlight search results