top of page
Search

Mock Services in Soap UI

The SOAP service mocking feature allows you to simulate a SOAP service by creating a mock service.




Uses of Mock services in Soap UI:

  • 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.

Let's create Mock services.


Step 1:

Right click on the SOAP Interface and select Generate SOAP Mock Service

ree

dialog box appears, select the interfaces need to have mock responses and click OK.

ree

Set a name for your mock service,

ree

You can see the MockService created for the selected interface.

ree

Step 2:

Click on the Response XML, you see the response tab with mock response.

ree

Edit the response with the value you want.

ree

Step 3:

To invoke mock services, double click on created mock service interface and click on green play button, you will see the test starts running on port specified while creating mock, and the red stop button enabled.

ree

ree

Step 4: Let us create a request that will be sent to the mock service. To do that, click Create SOAP Request in the operation editor.

ree

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.

ree

After the request editor shows up, you can submit the request by clicking green play button. Now you can see the endpoint automatically updated to local server.

ree

The mock service will then return the response you configured earlier.

ree

Customizing mock response:

You can customize soap response by adding groovy script in script tab.

Let's add a single line script to retrieve random data each time the request is executed.


context.setProperty("rate",Math.random())

${rate} is used in response xml to retrieve data from the script.


This is called a Property expansion and it's a very powerful feature in SoapUI. By inserting a property expansion in any element you can then fill the element programatically. Basically it tells SoapUI to use the current value of property rate.


ree

Execute the request, we could see different response every time we execute.

ree

Congratulations! You have created your first mock test.

 
 
 

Recent Posts

See All

Comments


bottom of page