Virtual services are crucial to testing practices. (See the recent post, 4 Key Reasons Service Virtualization is a Must for Agile Teams, for a great overview of why.) When it comes to creating a virtual service, one approach teams can use is recording. While this can be a great way to create a virtual service, it has some limitations in terms of the scope of the data set that can be held. This is largely due to the limitations associated with request-response pairs used with this approach.
Service Virtualization offers a feature called “Data-Driven Virtual Service.” This enables teams to turbo-charge their Service Virtualization investments. With this powerful tool, teams can address the data scenarios they need to effectively simulate production systems. This feature enables teams to use the Lookup or Refer command to reference an external data set, such an .xlsx or .csv file, and provide a response based on the values in the request.
In the following example, we’ll show how a country name can be entered as an input, the correct row in the table can be identified, and related details can be returned. Here’s a sample table:
Country Name |
Capital |
Currency |
Official Language |
Head of Government |
Afghanistan |
Kabul |
Afghani |
Dari Persian; Pashto |
President - Ashraf Gani |
Albania |
Tirane |
Lek |
Albanian |
Prime Minister – Edi Rama |
Algeria |
Algiers |
Dinar |
Arabic; Tamazight; French |
Prime Minister – Ahmed Ouyahia |
Andorra |
Andorra la Vella |
Euro |
Catalan |
Antoni Martí |
Angola |
Luanda |
New Kwanza |
Portuguese |
President – João Lourenço |
Assume that your backend service accepts the following request-and-response format.
Request |
Response |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webservicex.net/">
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
In order to fully virtualize your backend, you have a few options:
Approach |
Pros |
Cons |
Record with all the possible request parameters. |
Easy to set up recording. Works well for limited set of data. |
Doesn't scale for large volumes of varied requests. Takes very long time to record all possible inputs and responses. |
Start with a basic virtual service using a request-response (RR) pair and then deploy the virtual service in learning mode. |
Easy to create the virtual service and deploy. |
May take a very long time to capture all possible request-response pairs to be recorded and have the virtual service fully ready to replace the live system. |
Make your virtual service data driven. |
Quick—all the possible request inputs and corresponding responses can be exported from a database to a .xlsx or .csv file and power your virtual service. Flexible—incremental updates to your request-response data store could be handled very easily, just by adding rows to the data set and re-deploying the virtual service. Efficient—this is by far the most efficient way to manage large sets of request-response pairs. More realistic—by having support for large data sets readily available, the virtual service very closely mimics the real service. |
This can only be set up only from the portal. |
It is important to be able to test that the virtual service you create is working. Using Workstation, create a test case and add a single step: web service execution (XML). Then hit the end point of the virtual service deployed from step 1. Use the XML request from country-req.xml file. The virtual service would promptly return the recorded response.
The next step is to make your virtual service data driven so that it is even more powerful. At this point, the virtual service only knows about India. It must be given information about the remaining 202 countries of the world. Let’s see how to add more horsepower to your virtual service with some simple steps.
Prepare your data set as an .xlsx or .csv file, with the column names occupying the first row. For this specific example, I quickly prepared the sheet by taking all the data that is available here.
My data sheet looks like the example below. You can also access the file here.
Once the data sheet is ready, it’s time to rewire our virtual service by adding data-driven behavior. You do this by following these simple steps:
I hope you find this information useful, and that you are as successful and happy as I was when I got this process working well. Good luck.