Functional Testing

PDF Print E-mail
Tuesday, 06 October 2009 08:38
User Rating:  / 18
Rate this article: PoorBest 
Please read the instructions on how to create a soapUI Project and how to import WSDL’s before trying these steps.

 

Once you have a WSDL imported and a project set up, it’s time to create your first TestCase. Please note that in soapUI there are many ways to do many flavors of Functional Testing; it can be used to validate very narrowly; each web service request and response on its own in Unit Testing, or widely; for a number of requests in sequence in Integration Testing. Further, you can add scripts using either Groovy or JavaScript that can enhance your tests in any way you want, for example interact with external systems or perform complex test-flow logic.

We will continue where we left off in the first "Getting Started" document. We just had created a project and imported the Amazon Web Service. In this tutorial we are going to learn three things:

  1. Create a test from a request in your WSDL
  2. Add an assertion to the test
  3. Run a test

1) Create a test from a request in your WSDL

  1. Expand the Web Service Interface by clicking on the plus sign next to it in the Navigator, plus . Double click on the request . In the workspace you should now see the request editor. Please note that we’re using soapUI Pro and the form based view only is available from soapUI Pro.

    Request_Open
  2. Select Add this request to TestCase figure3b_icon in the request editor.
    add_this_request
    Adding a Request to a TestCase will open the Create TestSuite dialog.
  3. In the Create TestSuite dialog, enter a name for your TestSuite. Click OK.
    Create TestSuite Window in soapUI
  4. In the Create TestCase dialog, enter a name for your TestCase.
    Create TestCase Window in soapUI
  5. In the following dialog Add Request to TestCase window, click OK.
    Add Request to TestCase
    soapUI will now generate a TestSuite and TestCase for you and the request will be added as a TestRequest. This is a copy of the request we have in the Interface. A TestCase Editor will also open with your new TestRequest.
    TestCase in Navigator
Add an Assertion to a test

2) Add an Assertion to the test

Now that we’ve created and run our first test, let’s add a validation of the response, what in soapUI is called an assertion. Start by closing down all windows you might have open in soapUI.

Info:

In soapUI an assertion is used for validating the response in your test. There are several assertions such as: Schema Compliance, Simple Contains, Simple Not Contains, SOAP Fault, Not SOAP Fault, SOAP Response, Response SLA, XPath Match, XQuery Match, Script Assertion, WS-Security Status, WS-Addressing Response Assertion and WS-Addressing Request Assertion

  1. Double Click on you Test Request. This will open The Request Editor.
  2. In the request editor, Click the Add an assertion to test request button.
    add assertion to test request in soapUI
  3. Select Schema Compliance from the drop down in the Select Assertion Dialog.
    select Schema compliance Assertion
  4. In the Configure Schema Compliance Assertion Dialog, click OK, this will validate against the schema in the WSDL you imported earlier.
    Configure SchemaCompliance Dialog
  5. Once you’ve added the assertion, run the request to validate the response by running the test and if the request and all assertions are successful, the SOAP Icon on the request tab should turn green, as should the SOAP Icon in the Navigator and the Assertion Header in Request Tab.
    soapUI after running assertion

Tip:

You can see how many assertions you have in a test by looking at the assertions tab. The number of Assertions is written on the tab "Assertions (2)"

Read More 3) Run a test

We're getting pretty close to having a proper test, but let's just work on it some more in order to make it a proper test.

  1. If we examine what we've run before, we can see that we haven't actually sent any data. Let's create a test that has data input and that verifies the response. Let's start by adding another Assertion; click on the Assertions Tab assertions_tab. This will reveal the Assertions Inspector which at the moment contains 2 assertions. Let's add a third by clicking the Add Assertion button
    add_assertion_inspector
  2. We'll add the most simple test for checking the contents of a response, which is called the Contains Assertion. The Contains Assertions checks the entire response, including the XML for a string, as a tool, it's blunt but very easy to use.
    Checking Response for content
  3. Let's add a search for "Madrid" in the response, since we don't know how the reponse will be formatted we'll tell soapUI to look ignore cases.
    Contains assertion dialog
    Save the Asssertion.
  4. As you can see the assertion fails!
    failed assertion
  5. This is to expect, we haven't created a proper reqest yet, as you can see above we're sending the PLaceName "?". Now let's send something that produces the expected result in the response; "Madrid". Add the text "Madrid" to the PlaceName element in the request.
    request with data
    The actual message looks like this:







    Madrid

  6. Run the request by clicking the Run button. The assertion should now be Green since the PlaceName in the response contains the Text Madrid
    Response with data in soapUI
    Tip: If a Assertion fails, the Assertion tab will expand and show the Assertion Inspector to highlight the failed assertion.
  7. Also try Running the TestCase from the TestCase Editor
    TestCase Editor
  8. or from the TestSuite Editor
    TestSuite Editor

 

Last Updated on Wednesday, 17 March 2010 15:12