In this post I will be discussing on doing functional testing on SOAP web-services using the SoapUI tool. See my previous blog to learn how to create a web-service project. Here, I will be using the sample project that I have created in my previous blog.
There are many tools available in the marketplace today for testing web-service projects. You also can build your own stand-alone or web clients to test web-services. SoapUI is a noble product that was used to test web-services in software industry today. This tool was developed by SmartBear Community and available in both open-source and commercial version (Pro version). You can download the tool from here. Obviously, there are so many added functionalities available in Pro version rather than free edition. In this tutorial I will be using the Pro version to demonstrate the test cases. SmartBear also gives the Pro version for a 14-day free trial. In this blog I will be showing a basic functional testing on SOAP web-service.
- SoapUI Installation
Download the product from this location http://www.soapui.org and run the downloaded setup. Installation steps are easy as any other typical software installation.
- Run SoapUI application after installing successfully. The starting screen will look something like this for the version: SoapUI Pro 5.1.2.
- Configure the SOAP project
Let’s set up our SOAP project within SoapUI.
First, navigate to File ⟹ New SOAP Project. You should see several other new project options in the pop-up window. ‘New REST Project‘ lets you create a RESTful Web Service project (REST is another type of web-service framework) and ‘New Generic Project‘ allows you to create a blank project & later decide the type of the web service that you are going to test. We are selecting ‘New SOAP Project‘ because here we are going to test our SOAP project that was developed in previous blog.
When the New SOAP Project window pops-up, give a name for your SoapUI project and the path of the WSDL file that we have generated in previous blog. You also can provide the URL for your WSDL file if you have it deployed on an application server. Make sure you select the ‘Create Requests‘ checkbox, that will create some sample requests for our project. Click OK once everything is set.
Now you can see our SoapUI project is in the Projects Navigation Pane with the web service methods and sample requests. The Requests mentioned here will be the callers of our web-service methods that was hosted on an application server. It passes requests to those particular methods/services and will get a response.
- When double click on the SoapUI project, you will see a window with several tabs in it.
◘ Overview tab: Gives a brief information about your project, WSDL file, number of test suits and etc.
◘ Environment tab : This will have all your service connection details. You must mention the environment where the web services being hosted. Default environment will be localhost.
◘ TestSuites tab : Displays every test suite that you have created.
For the moment, we can ignore the other tabs that wasn’t listed above.
- The Requests
Double click on the Request1 under sayHello method that we get when created the project. The requests in SoapUI will represent in forms. This form accepts values for the parameters/arguments of the web-service method.
We can straightly provide the values to these parameters and test our method directly from there, but as a best practices we don’t do that. Instead, we create some test suites and provide sample values to our method params. And then we submit requests to the hosted web-service module.
- Test Suites
A Test Suite in SoapUI is nothing but a module that groups our testcases/scenarios that we are going to perform. The easiest way to create a Test Suite is to right click on the sample request (that is Request1 in our example) and then select ‘Add to TestCase‘.
Give a name to the test suite in the pop-up window. Once you click OK it will ask you to provide a name for the testcase.
After that, provide the Request details. Just give the name and leave the rest as it is.
Now that we have created a test suite and a testcase with a request.
There’s another way to create test suites:
◘ Right click on your SoapUI project and select ‘New TestSuite‘ from the menu.
◘ Give a name for the test suite and click OK button.
◘ If you have noticed, this time it doesn’t ask for the testcase name and request name. This is because, here we are creating an empty test suite, where we have to include details later-on.
◘ To create a testcase in this test suite, just right click on the test suite and select ‘New TestCase‘. Name it and click OK.
◘ Our test case is ready. Now we need to create a request. For that, just right click on that particular test case ⟹ select ‘Add Step‘ from the menu ⟹ click ‘Test Request‘. Now you will get the following pop-up window.
◘ Select the operation/service method for the test case and hit OK button. Give your request name and leave the rest in default.
◘ Our testcase is almost ready. Now, when double clicking the new request, we will see the same form that we saw previously above.
- Start Testing
Provide a string value to the above request form (hence our sample web-service project accepts only one string parameter). Click the green arrow that is there in the top left corner as shown in following figure. As you can see, we have received the response successfully from the server. The response is on the right side of SoapUI window.
Following is the Tomcat server logs for the above test.
You also can execute many test cases at once. Just double click on the test suite and click the green arrow (play button). This will execute every testcase available in that test suite.
If you want to run every test suite, then double click your SoapUI project and go to the TestSuits tab. And then click the green arrow (play button). This will run every test case from every test suite in the project. The outputs will be greener if the test cases were successful. Otherwise, it will become red if there’s a failed test.
- Test Assertions
We can create assertions to validate our testcases in SoapUI. Assertions are conditional statements that you define on each testcase. If an assertion fails then the testcase will be failure. If you create multiple assertions for a particular testcase, then all those asserts should pass through. If a single assertion fails, entire testcase fails. SoapUI provides few predefined assertions that you can apply to your web service testcases.
To create an assertion, double click on a request that you want to apply the assertion. And then click on ‘Assertions‘ tab in the bottom of the screen as shown below. By default, there will be one assertion that will be used to verify/validate the response. Then click on this small symbol as shown in following figure.
You will see ‘Add Assertion‘ pop-up and there you can select various types of assertions that are available in SoapUI.
For our example project, I am going to add an assertion to validate the Request parameter to contain the word ‘hello‘. To do this, we need to select the ‘Contains‘ assertion under ‘Property Content‘. Then click ‘Add‘ button. From the pop-up, give the content that you want the SoapUI to validate (I have given the ‘hello’ string). Then click OK button.
Now you will see this assertion has being added to your project. According to this validation, your test case will fail if your request doesn’t contain the word ‘hello’.
These are the basic concepts of testing a SOAP web-service using SoapUI tool. This tool contains lot more features that can be discussed separately.