Using SoapUI for Web Service Testing

SoapUI is a great tool which can be used to test web services. In this post I'll show you how to set up SoapUI project for WS testing.

Create new project from File ->New SoapUI Project, and in "New Project Dialog" give name and the location of the WSDL file.


You can find the sample wsdl file I used for testing in github https://github.com/sandarenu/soapui-test.

Web Service Mocking

Service mocking is required when you are writing a web service clients and either you don't have the web service implemented or you don't have the access to the real service. Here's how to do that using SoapUI.

Create Mock of the web service by right clicking on the project and selecting 'Generate MockService'.

Once mock service is created you can mock the operations by clicking on the small icon in the service mock dialog.




Double click on the operation you just mocked and you'll get a dialog to configure mock responses.
You can configure any number of mock responses and then select how those response to be dispatched when our mock service receives WS request. There are many dispatching strategies available such as "Script", "Sequence", "Query Match", etc...

When you do some integration testing you need your mock service to respond based on different parameters of the requests you send. In such cases you can either use "Script" or "Query Match" dispatch mechanism.

Web Service Testing
We can use SoapUI to create test cases to test a Web Service we developed. To create a test suite right click on the project and select "New TestSuite" from the context menu. Then right click on the test suite we just created and select "New TestCase".



Once we have created the test case we can add test steps to it. Lets add a test step to test time for time zone 'lk'. Right click on the test steps dialog and select "Test Request" and create the request you want to test.
Once test request is created we can add assertion step to it. Click the "Assertions" button at the bottom of the test request editor.


Right click on the assertion editor and add "xPath Match"

 Put //Time as "xQuery Expression" and put value you are expecting as "Expected Result"

Now you can test this request using the Mock WS you created before. Start the mock service by clicking on the small green arrow found in the top of the "TimeServiceMock". Then open the test case you created above by double clicking it. Then run the test case again by clicking small green arrow in the to of the dialog box.


If every thing went well you'll be able get success result for your test case.

This is just the start. You can then add more test cases and assertions and improve your test suite. SoapUI site has good documentation on how to do functional testing. http://www.soapui.org/Getting-Started/functional-testing.html
You can refer that and get more information.

You can also find the SoapUI project for this example at https://github.com/sandarenu/soapui-test. Download it and open it using "File -> Import Project"

Happy Testing.....
 

Reader Comments

If you are looking for just the mocking of a SOAP based web service, have a look at the below application on SourceForge.

http://sourceforge.net/projects/easymocker

Web Service Mocker is an easy to use, completely web based SOAP web service mocking utility. This utility is found very useful in a SOA development environment during unit test, component integration test and non-functional requirement testing.

another option would be to use Mockito framework, sample code can be found here Mocking .NET WebServices with Mockito



Tribune to Heros

Tribune to Heros
We will never forget the sacrifices you made to protect our country....

Subscribe


Get Google Toolbar Button

Enter your email address:

Delivered by FeedBurner