Enroll in Selenium Training

In the software world, to ensure that we are building the right system, one needs to validate the system continuously. Additionally, the validation ensures that the expected output is the same as the actual output. Moreover, these validations perform with the help of "Assertions," which make sure that the product met the customer's expectations. Subsequently, in this article, we will understand the concept of assertions in the context of SoapUI. In addition to this, we will also cover a few of the assertions which are specific to REST WebServices.

Below are the topics which we will be looking upon in this article :

  • What are assertions?
    • What are assertions in SoapUI?
    • How to add assertions in SoapUI?
    • What are the different types of assertions supported by SoapUI?
    • How to logically categorize SoapUI assertions?

What are Assertions?

One of the popular definitions of a test is "a test is a condition that must be verified to confirm conformance to a requirement." So, what is a test assertion in this? It is that condition or the checkpoint which needs verification during the test execution. We, being QA, perform multiple validations or assertions during our daily testing activities, be it manually or automatically.

While testing a WebService, a web server receives a request, which in turn sends a response is received. Additionally, we validate specific criteria on this response, such as the response code, the data returned in the response, the schema of the response, etc. This validation in the test cases is known as the assertion of the tests.

What are assertions in SoapUI?

Being an API or WebService automation tool, SoapUI also provides specific validation points that can validate the response of various types of TestSteps. These validation points are known as "Assertions" in SoapUI.  Additionally, in SoapUI, we can use assertions for the following validations:

  • Verify response codes.
  • Validate response headers.
  • To Validate individual values in the response bodies.
  • Validate the schema of the response.
  • Validate the execution time of the request.

How to add assertions in SoapUI?

As we mentioned earlier, assertions in SoapUI add at the TestSteps level. After adding the TestStep for either the SOAP Request or the REST Request (as mentioned in the article "Creating and Structuring TestCases in SoapUI " ), we can add the assertions by following the steps as mentioned below:

  1. First, navigate to the bottom of the TestStep screen. After that, click on the "Assertions" option, as shown by marker 2 in the following screenshot:

Add Assertions on a TestStep in SoapUI

  1. Secondly, click on the (+) icon, as represented by marker 1 in the above screenshot. Consequently, it will open a dialogue box, as shown below:

Add assertion in SoapUI

  1. Thirdly, select the "Assertion" type in the left panel and select the corresponding assertion in the right panel. After that, click on the "Add" button.

  2. Fourthly, depending on the assertion type chosen, it will open a dialogue box to enter the condition of the assertion. Here, you can add the validation that needs to perform on the TestStep.

Note: We will cover details of how to specify the validation for all these types of assertions in future articles.

SoapUI supports a wide range of assertions. Subsequently, let's understand the necessary details of all types of these assertions in the following section:

What are the different categories of Assertions in SoapUI?

As seen from the "Add Assertion" dialogue box, SoapUI supports the following seven types of assertions in the current version of SoapUI:

Different categories of assertions in SoapUI

Let's understand various sub-categories under all these assertions:

Property Content Assertions in SoapUI:

First is Property Content. These types of assertions validate specific values in the content of the response. Following assertions are covered under this category:

Assertion Description
Contains This assertion validates the existence of a string in the response.
Message Content Assertion This assertion validates the complex content of XML messages.
Not Contains This assertion validates the non-existence of a string in the response.
XPath Match This assertion picks an XPath expression to select content from the target property. After that, it compares the result to an expected value.
XQuery Math This assertion uses an XQuery expression to select content from the target property. Consequently, it compares the result to an expected value.

Compliance, Status, and Standards:

The second is Compliance, Status, and Standards. These types of assertions validate specific SLA, schema, or standards. Following assertions are covered under this category:

Assertion Description
HTTP Download all resource This assertion downloads all resources, which are an HTML document (such as images, scripts, etc.) Additionally, they validate that they are all available in the response.
Invalid HTTP Status Codes This assertion validates that the TestStep received an HTTP result with invalid status.
Not SOAP Fault This assertion validates that the received message is not a SOAP Fault.
SOAP Fault This assertion validates that the received message is a SOAP Fault.
Schema Compliance This assertion validates that the received message is compliant with the associated WSDL or WADL schema definition.
SOAP Response This assertion validates that the received response is a valid SOAP Response.
Valid HTTP Status Codes This assertion validates that the TestStep received an HTTP result with a status code in the list of defined codes.
WS-Addressing Request/Response This assertion validates that the received request/response contains a valid WS-Addressing header.
WS-Security Status This assertion validates that the received message contained valid WS-Security headers.

Script:

The third is the Script. These types of assertions specify a customized assertion using a script. Following assertions are covered under this category:

Assertion Description
Script Assertion This assertion performs an arbitrary validation by running a script.

SLA Assertions in SoapUI:

Fourth comes SLA. These types of assertions validate Service Level Agreements. Following assertions are covered under this category:

Assertion Description
Response SLA This assertion validates that the received response time was within the defined limit.

JMS Assertions in SoapUI:

The fifth is JMS.  These types of assertions validate Java Messaging Services. Following assertions are covered under this category:

Assertion Description
JMS Status This assertion validates that the JMS request of the TestStep executed successfully.
JMS Timeout This assertion validates that the JMS statement of the TestStep did not take longer than the specified duration.

JDBC Assertions in SoapUI:

The sixth is JDBC. These types of assertions do validation of the Database connections. Following assertions are covered under this category:

Assertion Description
JDBC Status This assertion validates that the JDBC statement of the TestStep executed successfully.
JDBC Timeout This assertion validates that the JDBC statement of the TestStep did not take longer than the specified duration.

Security Assertions in SoapUI:

The seventh is Security. These types of assertions carry out validation of the Security breaches. Following assertions are covered under this category:

Assertion Description
Sensitive Information Exposure This assertion validates that the received message does not expose a piece of confidential information about the target system.

How to logically categorize assertions?

All the assertions, as mentioned above, can be logically categorized into the following categories based on what type of TestStep they are associated with:

  • Firstly, Test Specific assertions for REST services.
  • Secondly, Test Specific assertions for SOAP services.
  • Thirdly, Common assertions for both SOAP and REST services.
  • Fourthly, Test Specific assertions for JDBC.
  • Finally, Test Specific assertions for Mocked responses.

We will be covering the in-depth details of the major of these assertions and their implementations in SoapUI in the next articles.

Key Takeaways:

  • Assertions are the checkpoints for the validation of test cases.
  • Moreover, in SoapUI, assertions can add to the TestSuite level only.
  • In addition to the above, SoapUI supports various types of assertions, such as based on content, Compliance and standards, SLA and Security, etc.
  • Also, different kinds of assertions will be enabled only for specific types of requests only.

Conclusively, let's move to the next article, where we will cover the "Rest Services Assertions in SoapUI".

SoapUI Test Case
SoapUI Test Case
Previous Article
SoapUI - REST Assertions
SoapUI - REST Assertions
Next Article

Similar Articles

Feedback