Monday, January 31, 2011

Assertions in soapUI - Why? How?

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.
  Type   Details
 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='';


 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.


  1. good explanation about xpath assertion. Can u explain in a detailed way about x-query assertion.How to declare x-query expression?

  2. Lots of fantastic reading here, thanks! I was seeking on yahoo when I found your publish, I’m going to add your feed to Google Reader, I look forward to much more from you.

  3. i tried some x-query assertion without any success. will update whenever i have some working examples :-)

  4. GoodExplanation,can u provide example screenshots for more assertions with response

  5. Good explanation..Could you please help me to do a complete xml comparison in soapui.

  6. What kind of comparison? Matching an element value? Matching an attribute? Validating a data type via regular expression?

  7. Awesome... Thanks for the help

  8. Good explanation.Thanks for this.
    I have a question- how can i restrict to not allow a string in the int column?
    in the below eg 'Key' is the variable of datatype INT, but if i give string value in that, can i restrict it not allow string in the requset in the soapui?
    ex:Key in('JOHN')

  9. hi am new for this SOAP concept i need to knew how to use update query in the Activity.

  10. hi,we provide online training & video tutorial for soapui
    for free videos refer