SOAP Service Mocking

SOAP Service Mocking

SOAP Service Mocking

The SOAP service mocking feature allows you to simulate a SOAP service by creating a mock service. You can then run it either directly from SoapUI, or use the mockservicerunner.bat  command-line application.

You can use SOAP mock services to perform various tasks:

  • First thing first, create a web service prototype. You can generate a complete mock service using just a single request. In this case, you can implement and test clients much faster, since there is no need to create a complex working solution.
  • Secondly, develop and test client applications. You can simulate requests you want to test and prepare a number of various responses for them. These responses can contain scripts, custom HTTP headers, attachments, and other content. You can cycle or randomize the responses, or prepare specific responses for certain requests.
  • Lastly, test every aspect of your future service. With SoapUI, you can perform functional and load testing against a mock service before even creating an actual live service.

Share and Distribute Mocks

If you need to share your mock with other members of your team or even with partners and customers, you can easily save the mock you have created to a WAR file. You can then deploy this WAR mock service in any Java server environment – it will run even without SoapUI.

Create Scripts

You can enhance your mocks via scripts. Scripts allow you to simulate almost any behavior, including dynamic results, random errors, responses containing variables, and so on.

Sample SOAP Mock Service

In general, a mock service simulates a live service by exposing a number of mock actions. Mock actions, in turn, contain a number of mock responses.

Let us create a project with a sample mock service:

  • First of all, Select File > New SOAP Project.
  • Subsequently, in the dialog that appears, specify a name for your project in the Project Name edit box and enter the following address in the Initial WSDL edit box:

http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL

  • Click OK.

Sometimes, the currency convertor web service we use in this example may be down due to a huge amount of requests. If the Loading Definition window is displayed too long, use any web browser to check the availability of the service – that is, just copy the address, paste it to the address bar, and then try to visit the page.

 

  • Once the project you have opened appears in the Navigator, right-click any SOAP interface and select Generate SOAP Mock Service.
  • The Generate MockService dialog will appear.
  • Click OK.
  • In the next dialog, specify a name for your new mock service and click OK.
  • A mock service containing one operation and one request should appear in the Navigator. It is currently inactive. You can edit the mock service before running it – to do that, double-click the name of the mock service.
  • In the mock service editor, you can see a list of operations of the mock service, as well as request and response logs. Double-click the operation to see a list of responses associated with it.
  • Double-click it to open the response editor.
  • The response editor is similar to the request editor. In the Incoming Request view, you will see the last request sent to the serivce, including the header and attachments. To the right, there is the response itself. You can modify its value as you wish – for example, replace ? with “two dollars”.
  • Now you can check if your mock service is working properly. To do that, go back to the mock service editor and click Run. This will start the service. To stop the service, click Stop at any time.
  • Let us create a request that will be sent to the mock service. To do that, click Create SOAP Request in the operation editor.
  • The Open Request dialog will appear. Use it to open one of the existing requests in the project – that is, select a request from the drop-down list, then click OK.
  • After the request editor shows up, you can submit the request by clicking Run. The mock service will then return the response you configured earlier.
  • Check the response editor – it should now show the request you have sent in the Incoming Request view.
  • Congratulations on creating your first SOAP mock service!

Make your resume stand out and become a Certified SoapUI Testing Professional. Try free practice tests here!

A great career is just a certification away. So, practice and validate your skills to become Certified SoapUI Testing Professional

Go back to Tutorial

Share this post
[social_warfare]
Maven
RESTful Mocking

Get industry recognized certification – Contact us

keyboard_arrow_up