What is Mocking

In general, mocking is creating a virtual service that works like a real service. A mock service imitates a real REST or SOAP API – it contains definitions for operations that clients call, receives requests, and returns simulated responses.

Note: In the SoapUI documentation, mocking can also be called isolation, virtualization, or simulation. All these terms refer to the same SoapUI feature.

Advantages of Mocking

  • You can create client code and tests before creating an actual service. This means you can create tests for operations that have not been implemented yet while developing your application. In other words, mocking allows you to perform test-driven development.

  • You teams can create and test features during application development simultaneously. While developers are working on the service, your QA team can create tests to have a full suite of tests when the service is ready for testing.

  • You can create tests for unavailable resources. With mock services, you can create tests for operations and endpoints that are unavailable because of some errors, or because they are behind a firewall or in a restricted network. A mock service, in turn, can be located anywhere – even on your work computer.

  • You can create demos. Using a mock service is a convenient way of making a demonstration of what exactly you are going to create. You can try out various scenarios and design solutions.

  • You can deploy your SoapUI mock as a WAR file on any computer where a Java virtual machine is installed to provide your service to customers or partners. This can be done if you cannot allow your customers or partners to access your test system for some reason.

  • You can isolate some subsystems of your service. This can be useful if you need to test some feature of your web service, and you do not want the other system components to affect it.

  • You can test a live environment before implementing an actual service. Using a mock service in a live environment, you can find out if all network resources, the server and configuration are prepared properly. This can help you get rid of technical problems before putting the web service into production.

Disadvantages of Mocking

  • You may have to duplicate your work. After using a mock service for some time, you will have to replace it with an actual service. With this in view, consider the efforts you put into the mock service – for most purposes, the mock service containing only the basic functions will be fine.

  • You will have to deploy and run your mock service somewhere, unless you plan to work with the mock service locally. In some cases, it might be an issue to find a suitable machine for that purpose. However, since you presumably have a server you will use to run an actual server, you can run your mock service on it as well.

  • A mock service is just a representation of a real web service. For that reason, it cannot be accurate to the maximum – it does not take into account the service specifics and may contain various bugs. The primary purpose of a mock service is testing, so this service usually lacks complexity of a live environment.

  • With there is a functioning mock service, it may be tempting for management to extend its functionality and move the mock service to a live environment. Do not do this! Any mock service is a simple testing environment that is not designed to work as an actual service.

Start Mocking Now

To learn how to create your first mock service, see the following sections: