Chapter 9. Service Mocking

As we move forward with test automation of SOA based applications we face several challenges to automate business flows. A few of these challenges can be answered by service virtualization and service mocking.

Service virtualization is a matured and a more detailed process to help in testing and test automation, whereas in service mocking stubs are made by considering test cases or test suites.

In this chapter we will learn how to create a mock service with different techniques/dispatch methods and deploy them.

So, before we move forward, we may well ask why we need service virtualization or service mocking.

Let's take a look at a few of the challenges faced during SOA testing and test automation:

  • No access to the third-party service
  • All the services are not ready, hence integration cannot be tested
  • Dependency on an external system which is not in control of the test team
  • Cost to be paid for accessing certain systems in the test environment

Because of the preceding issues, most of the time the test cases are not completely executed. To address the challenges we use service mocking or service virtualization techniques.

Now let's see what SoapUI has to offer in this area.

SoapUI offers a service mocking facility in its open source version.

Let's have a look at the advantages of mocking:

  • Test sets can be created early
  • Early identification of bugs as you get the feel of a live environment via stub
  • Testing independent services is possible
  • Helps at the time of PoC when we don't have the real environment
  • Parallel teams can work at the same time as the developer works on their uncompleted work and QA, mock the uncompleted service and move ahead

So let's see how we create a mock service in SoapUI.

Creating mock services in SoapUI

Lets now see how to create mock services in SoapUI.

A pre-requisite is that the WSDL is already loaded in the project. In the following example, we have loaded the WSDL in the tool:

  1. Right click on the binding and verify that below options pop up:
    Creating mock services in SoapUI

    As shown in the figure preceding, select Generate SOAP Mock Service.

  2. Verify that the options screen below pops up after the user has selected Generate Mock Service:
    Creating mock services in SoapUI

    On the preceding screen you can see the option to select a single as well as multiple operations. To mock you can add and configure your service accordingly here such as if you want to configure the path or the port. Click on OK to proceed forward.

  3. On clicking on OK you will be directed to the following page:
    Creating mock services in SoapUI

    Now on this screen you may select any operation for which you want to further configure your mock stubs. Also from here you can change the configuration of the mock service endpoint and port details by clicking on the Creating mock services in SoapUI settings icon and you will see the following configuration window appear:

    Creating mock services in SoapUI

    Now let's select the first operation from the previous screen GetCityForecastByZip.

  4. Once you have clicked on the operation you will be navigated to the following screen:
    Creating mock services in SoapUI
  5. On the preceding screen we have a Dispatch: option. In the Dispatch option dropdown you may select any of the dispatch types based on your stub requirement:
    Creating mock services in SoapUI

    Note

    We will study each dispatch type later in the chapter.

    So now if we need to change our response values, or response, how do we change it?

  6. Changing the response values: In order to change the response values you need to click on Response 1 as shown in the following screenshot:
    Creating mock services in SoapUI
  7. Once you click on Response 1 you will be navigated to the following screen:
    Creating mock services in SoapUI

    On the preceding screen if you want to change the response you can edit the response data and put any value there, shown in the following screenshot:

    Creating mock services in SoapUI
  8. Once you have set the response, as per your need, your stub is configured. Now let see how to run the stub:
    Creating mock services in SoapUI
  9. Double click on the binding value named WeatherSoap MockService and verify that the screen following pops up:
    Creating mock services in SoapUI
  10. On this screen click on the green play Creating mock services in SoapUI button to run the mock service.
  11. Now to verify your stub, go to the request editor, open the request and run the request against the correct endpoint:

    Note

    Note: PUISN001SI-L1 in the following screenshot can be a localhost or the IP of the machine where you want to host the service.

    Creating mock services in SoapUI
  12. Once you run the request you will see the following response:
    Creating mock services in SoapUI
  13. Now in order to check if your stub is really working, shut down the stub by clicking on the red button on the following screen:
    Creating mock services in SoapUI
  14. Once you have stopped the service, in order to verify if the stub works correctly or not, rerun the service and you will get the following message:

    <html><body><p>There are currently 0 running Mock Services</p><ul></ul></p></body></html>

The preceding steps confirm the successful creation of a stub for a particular operation. You can replicate the same steps for creating stubs for other operations as well.

Now let's have a look at a different dispatch method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.252