Mock Web Service With soapUI

Mock Web Service With soapUI explains about how to create mock service using soapUI

Mock service is a dummy or approximate implementation of actual webservice, it helps you to simulate the service before actual webservice is developed

When & Why Mock Web Service Required?

If your webservice (WSDL) is done by some third parties and, you only got WSDL with some sample request/response. In this situation you can use mock service with soapUI, because our aim is to start the development without waiting for the other team to complete the service.

In this Mock web service with soapUI example we are using Groovy script for testing complex test cases

Required Libraries

You need to download

  1. soapUI 4.5.1

Select File->New soapUI Project, just provide a name and browse WSDL from file system

Create soapUI Project

Generate MockService as per below screenshot

Generate MockService with soapUI

You can change the port and name binding here

MockService with soapUI Options

You can modify the MockService name

Modify MockService Name

Create New MockResponse, Here I am creating 3 dummy responses as Sony,Rockey,Rose

Create New MockResponse

You can modify the MockResponse on this window

Modify MockResponse Name

Here I am creating 3 dummy responses as Sony,Rockey and Rose

soapUI MockService

Here I have edited the name as Sony (You need to repeat this step for all 3 responses like Sony,Rockey and Rose)

Modify MockService Response

Starting the MockService with soapUI

Start MockService Inside soapUI

Just browse http://localhost:8080, you can view the running service

Running soapUI MockService Modify soapUI MockOperation Editor

Paste the below code in Groovy inside MockOperation Editor

def xmlHolder = new mockRequest.requestContent )
def namePrefix = xmlHolder["//*[local-name()='name']"]"Search request with name prefix:" + namePrefix)
if (namePrefix == 'Rockey') {
    return 'Rockey'
} else if (namePrefix == 'Rose') {
    return 'Rose'
} else {
    return 'Sony'

Add Groovy Script On MockOperation Editor

You need to modify the endpoint (See the screenshot)

Run service as Rockey, you can see the output, also try with request as Sony and Rose too,,

Mock Webservice Request Response

2 Responses to "Mock Web Service With soapUI"
  1. Sijo 2013-10-21 10:53:16.0
  1. admin 2013-10-22 10:53:16.0

Your email address will not be published. Required fields are marked *