Forum Discussion

catty's avatar
catty
Occasional Contributor
16 years ago

Assertions help

Hello could someone pls help me on Assertions??? What needs to be included and why are they needed..? Should we include all the assertions in our test case??

3 Replies

  • admin_1's avatar
    admin_1
    Occasional Contributor
    Hi Catty,

    An assertion is very important. It is your way of saying "does the response contain what i want it to contain?" and if an assertion fails it's proof that the Web Service does not work.

    My rule of thumb is that; Yes you should include assertions.

    Now, you can group assertions into different categories:

    Base Assertions:

    These assertions coudl or should always be there, even when you have other assertions.

    Schema Compliance
    Validates the response message against its xml schema.
    Cab always be used. If there is a mismatch between the message and what is returned it will fail
    SOAP Fault.
    Checks that the response is a soap fault. Really simple way to catch when the service is throwing a fault.
    Not SOAP Fault
    Checks that the response is not a soap fault. Good when you have a negative test.
    SOAP Response
    Checks that the response is valid SOAP Response. Can always be there.

    Intermediate Assertions
    These are medium complex assertions. I encourage using at least one of them.

    Simple Contains
    Checks for the existence of a token. Really Simple. Is there the text "Catty"
    Simple somewhere in the message. Very Simple, but not very exact.

    Not Contains
    Checks for the non existence of a token. The opposite of above. I don't want "Catttty" in the response.
    Response SLA
    Simple. Checks the response time to be under a specified value; I want it to respond in a second, if not report it as an error.
    XPath Match
    The above where simple, but not very exact. XPath match is used to be exact; I want the element Username to be "Catty". Matches the result of a specified XPath expression against a predefined value. This is more complex, but soapUI Pro makes this into a simple point and click exercise. This is the assertion I always use and the one I live by. Or rather used to live by when I still worked in testing.

    Advanced
    Here are the Asseertions for more complex tasks.
    XQuery Match
    Good when you have large amounts of data in the responseMatches the result of a specified XQuery expression against a predefined value
    Script Assertion
    Allows a custom Groovy script for asserting the message exchange. Although complex it is still useful for more complex calculations, how do you know that the SSN return actually is a proper SSN? do a Script assertion.
    WS-Security Status
    This is for when the Web Service Implements WS-S. Checks that incoming WS-Security processing was successful
    WS-Addressing Response Assertion
    Checks that the response has valid WS-A header properties. This is for when the Web Service Implements WS-A.
    WS-Addressing Request Assertion
    Checks that the request has valid WS-A header properties.This is for when the Web Service Implements WS-A

    /niclas
    eviware.com
  • catty's avatar
    catty
    Occasional Contributor
    You are a star.. That makes sense even to the dumbest.

    Thks a lot..
  • catty's avatar
    catty
    Occasional Contributor
    0ne final question pls...

    Can you please describe XPath with a example on how to declare it in the Xpath Expression. Does my question makes any sense??

    Thanks