Before diving deep into the soapUI Assertions topic, let me throw some light on the word “Assertion” itself. This word may not be known to many of entry level testers. So we will go with the dictionary definition of the verb “Assert” which then forms the noun “Assertion”.
Assert: To declare or affirm solemnly and formally as true
Assertion: The act of affirming, asserting or stating something
From the above provided definition, we can conclude that Assertion in soapUI would help testers to affirm/confirm the correctness of test results/response. I assume that this answers the first part of the question “Assertion in soapUI – Why”.
Now moving to the second part of question “Assertion in soapUI – How”, which would require a detailed explanation. soapUI 3.6 supports around 14 different types of assertions, however in this blog we will cover the very basic & frequently used Assertion types. Below I have provided some assertions types and the detailed information about them.
|Schema Compliance||validates the response message against the definition in the WSDL and contained XML Schema|
|SOAP Response||checks that the response is a valid SOAP message, always use this to make sure you are actually getting a response (if no assertions are added a connection error will not cause a failure).|
|SOAP Fault||checks that the response is a SOAP Fault (for negative testing)|
|Not SOAP Fault||checks that the response is not a SOAP Fault. Never use this assertion type together with SOAP Fault, since they will have opposite results always [i.e., compliment of each other]|
|xPath Match||validates the response message against the data returned by xPath expression & any tag in response.|
|xQuery Match||validates the response message against the data returned by xQuery expression & any tag in response.|
|Contains||validates the response message contains a particular string or regular expression provided in ‘Contains’ assert condition.|
|Script Assertion||validates the response message against data returned by the code of lines written in Groovy script. Useful to verify the response data against the Database which can fetched using Groovy script|
Assertion can only be used with either Test Step or Test Cases. It is not possible to put an assertion in the request template under the Binding Operation/Method. To put an assertion, click on the icon (refer attached screen shot) next to “Run the Test Step”
Now refer the below attached 2 screen shots for an example of xPath assertion in soapUI. Any xPath assertion would comprise of 2 things – (a) is xPath expression to evaluate the XML file and fetch the required data. (b) the expected response which needs to be compared against the xPath expression result.
I have used the following xPath expression :
declare namespace ns1=’http://search.yahooapis.com/ImageSearchService/V1/imageSearch’;
I hope these snapshots & the blog content would be of some help for you to understand the “Assertion in soapUI “ .
EndNote: Assertion are very useful while performing the regression testing and to validate the test results without digging into much details.