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 (mockservicerunner.sh in OS X) command-line application.
When Mocking is Required
You can use SOAP mock services to perform various tasks:
-
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.
-
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.
-
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.
Note: Please keep in mind that SoapUI mock services are not designed to be implemented as actual live services. Even if a mock service works correctly, it does not mean the actual service built atop of that mock will work as required. It also does not provide any actual functionality except for sending the predefined responses.
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.
Share your mocks with 3rd party developers and other teams | Learn more about ReadyAPI (video)
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.
SoapUI Open Source
- Support for SOAP and REST API Testing.
- Easy multi-environment switching.
- Detailed test history and test comparison reporting.
SoapUI Pro
- Support for SOAP, REST, and GraphQL API Testing.
- Easy multi-environment switching.
- Detailed test history and test comparison reporting.
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:
-
Select File > New SOAP Project.
-
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.
Tip: 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.
As you can see, SoapUI specifies most of the settings automatically. 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.
-
Currently, there is only one response.
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 . This will start the service.
Tip: To stop the service, click 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 . 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!
No one knows APIs better than SmartBear. Find out what our Pro version of SoapUI can do to improve your testing.