10 June 2009 - 3.0-beta-2 user guide eclipse intellij netbeans maven download nightly forum bugs blog sf.net eviware


Eviware Logo

Getting Started with Web Service Mocking

In soapUI 1.7 we introduced the possibility to create mock implementations of operations and entire services with a combination of static response messages combined with Groovy scripts, attachments and custom http headers. This opens for a number of usage scenarios, including:

  • Rapid Web Services Prototyping; generate a complete static mock implementation from a WSDL in seconds and add dynamic functionality using Groovy.
  • Client testing/development; create mock implementations of desired operations and set up a number of alternative responses (including scripts, attachments and custom http headers). Clients can be developed and tested without access to the "live" services. Responses can be cycled, randomized or selected with XPath expression from incoming request
  • Test Driven Development; Create soapUI TestSuites and TestCases against MockServices before or during the actual services being implemented
  • etc...
Start soapUI Testing
Did you know?

In soapUI Pro you have two more request and response editors; The Form editor and the Outline Editor.

Both will improve your productivity and make Web Service Testing more fun.

soapUI Pro contains productivity enhancements as well as offers Professional World Class support. contains productivity enhancements as well as offers Professional World Class support.

Try soapUI pro to soap test

In the following example we will create a mock implementation of an existing service, tailor the mock response with some Groovy and call the mock service from within soapUI. Start by creating a new project for the publicly available CurrencyConverter at http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

New Web Service Project

Create a MockService

After importing, you should get an interface with one operation and request. Right-click the interface and select the "Generate MockService" menu option:

Generate a Web Service simulation from WSDL

This opens the following dialog which lets you specify the local port/path for the create service (can of course be changed later..);

Genererate a Mock Web Service

Just leave the suggested values, for this and coming dialogs.. When the MockService has been created, you will get a new tree hierarchy similar to the the initial Interface, but with grayed icons... The MockService contains a MockOperation corresponding to the operation in the original interface and soapUI has also created one MockResponse for this operation from its schema... Double click both the MockService and "Response 1" tree nodes to open their corresponding editors, after some moving or resizing around you should be able to arrive at the following:

Editing a Web Service Mock Response

The MockService editor (top left) contains a toolbar, a list of all operations for the service and a request/response log which logs all incoming requests that have been handled by the MockService.

The MockResponse editor is very similar to the standard soapUI Request editor (which can/will be confusing at first ;-), only the "focus" has been shifted to the response-tabs of the editor, since this is where the editing of the mock response will be done. The "Incoming Request" tab/view shows the last received request to the operation (useful for debugging client calls), including attachments and http-headers.

Invoke the MockService from within soapUI

In the screen above you can see the default response that has been generated by soapUI from the schema. Lets continue by just invoking this mock operation from within soapUI:

  1. Click the green arrow button in the MockService editor... this will start the service on the configured port/path which can also be seen in the log (this has already been done in the screenshot above..)
  2. In the MockResponse editor, select the left-most button in the toolbar, which will prompt to open one of the existing requests for the corresponding operation in your project. When opening the request, soapUI will automatically change its endpoint to the endpoint of the now locally running MockService
  3. Submit the opened request! If all goes well you should get the previously create MockResponse in the request editors response window:

Web Service Invocation

Switching back to the MockResponse editor and selecting its "Incoming Request" tab/view, you should be able to see the request that was posted to the MockService and handled by the corresponding MockOperation:

Response for soapUI Web Service Mock Response

Congratulations! Hopefully all went well and you now have your first MockService up and running... Feel free to modify the created MockResponse content and resubmitting the request to see that your changes are instantly available (no need to restart the MockService)

Customize the MockResponse

Let's continue by making the created mock response a bit more dynamic with a Groovy script. Switch to the "Response Script" tab in the MockResponse editor and enter the following:

Web Service Mock Response Scripting

Go back to the Mock Response tab and change the response body to

Web Service Mock Response Parameter

Now, when submitting a request to this MockResponse, the script will be evaluated and the generated rate value will be inserted into the outgoing response message;

Web Service Mock Response Expansion

OK... this should get you started with your first mock service... now you can continue with:

  • Adding some more responses to the MockOperation (via its right-button menu). Change the dispatch method through the MockOperation Options dialog
  • Add more dynamic script behavior (database or file access, input processing, etc...), attachments, custom response http headers, etc...
  • Generate a web service client with one of soapUI's tool integrations and call your MockService from there to see what message the client actually sends (and that it handles your response correctly)
  • etc...


Next: soapUI Sample Project