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='http://search.yahooapis.com/ImageSearchService/V1/imageSearch';
//ns1:Response[1]/ns1:ResultSet[1]/ns1:Result[1]/ns1:e[1]/ns1:FileFormat[1]

























 


 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.

9 comments:

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

    ReplyDelete
  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.

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

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

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

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

    ReplyDelete
  7. Awesome... Thanks for the help

    ReplyDelete
  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')

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

    ReplyDelete