Blog

Service Virtualization – Open source and commercial tools

Introduction

This POC (Proof of concept) tend to analyse different service virtualization available on the market.

Glossary

  • POC = Proof of concept
  • Service Virtualization = “A test double often provided as a Software-as-a-Service (SaaS), is always called remotely, and is never working in-process directly with methods or functions. A virtual service is often created by recording traffic using one of the service virtualization platforms instead of building the interaction pattern from scratch based on interface or API documentation.” (ref1)
  • Stub = “A minimal implementation of an interface that normally returns hardcoded data that is tightly coupled to the test suite.” (ref1)
  • Mock = “A programmable interface observer, that verifies outputs against expectations defined by the test.” (ref1)

Main feature to consider in Service Virtualization

  • Multi protocol (not only HTTP).
  • Record record real transaction to re-play them for testing purpose.
  • Learn and cache responses.

List of Service Virtualization (Open source)

None yet if we consider SV main features.

List of Mocks (Open source)

Name Download link Comments
Citrus Framework https://citrusframework.org Works with a large spectrum of protocols (http, jms, ftp, mail, etc…)
Hoverfly https://hoverfly.io/ Learn more
Wiremock http://wiremock.org/
Mockito http://site.mockito.org/  Java only
Mockey https://github.com/clafonta/Mockey
Mirage https://github.com/InternationalAirlinesGroup/mirage
Wilma https://github.com/epam/Wilma Dockerized solution
Nagual https://github.com/emanuil/nagual

List of Service Virtualization (Commercial)

Name Download link Comments
CA https://www.ca.com/us/products/ca-service-virtualization.html
HP SV http://www8.hp.com/us/en/software-solutions/service-virtualization/ Learn more
Tricentis https://www.ca.com/us/products/ca-service-virtualization.html
ParaSoft https://www.parasoft.com/solution/continuous-testing/
SmartBear https://smartbear.com/product/ready-api/servicev/overview/
Traffic Parrot http://trafficparrot.com/

List of Mocks (Commercial)

Name Download link Comments
Telerik http://www.telerik.com/products/mocking.aspx
Sandbox https://getsandbox.com

References

Samy Kacem

HP Service Virtualization

Install HPE _SV Designer 3.82 CE

  • Windows 2012R2
  • SQL 2012 Express SP1

RestApi

We will use the API from ft-demo-website project => API. We will explore HPE SV and We will virtualize 2 methods from the API:

  • Read list of books
  • Add a book

Read list of books

Original : http://../api/listBooks.php
This GET Rest Api provides a list of books

  • We need to configure HPE Sv to learn the service:
    • Go to Add a new virtual service…
    • Select I don’t have a service description & click Next
    • Select REST & click Next
    • Select agent HTTP Gateway because we want to simulate the endpoint.
    • Add in Real Service > Endpoints the original rest api as specified above & click Next
    • Start to learn by selecting Learn and create a call using the Virtual Service not the Real service
    • System is learning thanks to this unique call. You will see that you have been redirected to the real service. When it the system is learning it captures the call, redirects it, plays as proxy and records the answer.
    • Switch to Simulate now & do again the call using again Virtual Service url. As you can see, you are not redirected and it is providing the same content. Now the service is kind of cached. We can say this service is stubbed as per this definition.

Add books

Original : http//../api/insertBook.php?title=toto&author=tutu&edition=Sun%20Edition
This GET Rest Api adds a book with the content defined in the param. You create a new Virtual service as the step above. Then put the 2 services in Learning mode.
Before starting, reset the db using http//../api/createTable.php (this will not simulated), and start to alternate the call (list, add, list, add etc…) then switch to Simulate and redo the same pattern. You will see the system is redoing the same outputs.
Now lets trick the system. Call only listBooks.php, you will notice he will loop as per the pattern even we don’t use insertBook.php! We you could face some issue for complex Business Process. How you could solve it? By using script or data driven set.

Beyond a simple stub

After recording you can more data scenarios. You have 2 options that could be used even together:

Script (C# or Javascript) to add business logic.
Data driven set managed with an Excel file and you define all the possible request and response required for your test.
Data test strategy

If you are stuck with some poor data or it is hard to use test data. It could be a good tool to put in place and have a new data test set. Based on your test scenarios, you create all the set of data you want to have in requests and answers and you will have fairly quick your data test set. This should be consider when you are doing your test strategy.

Conclusion

It works perfect if you are doing automated test but if you are doing manual explanatory tests it will be wired.
If you need to put more business logic it is still possible. For each service virtualized, you can add scripts with business logic. But how far you want to replicate the business logic? This could be complicated if you need a perfect replication, that means you will have 2 technologies to maintain with the same business logic. You should avoid creating scripts and answer as much as possible with Data driven set. This will be more easy to maintain.

Samy Kacem

Hoverfly

Let’s do a quick overview on this open source tool for Service Mocking / Service Virtualization.

Pre-requirement

  • Using v0.11.0
  • For test purposes we are using ft-demo-website
  • Docker (if you want to use it, it is optional)

Introduction

There 3 ways of using Hoverfly:

  • Using mainly for stub purpose, we set a json file that configure the appropriate answer we want. Mainly there are static answers. You can see the demo.
  • Using as simple mock with middleware in python.
  • Have a more complexe mock for complex workflows using Hoverfly Java.

Demo

For the demo we took the first way of doing, just stubbing. You can see the demo. We are mainly 2 simples configurations:

  • We record a api call. We have created a bash script that generate the json file you will need to reuse for replay purpose.
  • We replay the api call. We have created a separate bash script that start locally a replay api call. It will use the json of the first step.

That’s it!

Docker

Now when you have your json for replay you can create a docker for mocking. Just one single command line:

docker run -d -p 8888:8888 -p 8500:8500 spectolabs/hoverfly:latest -import ${HOVERFLY_JSON_URL}

References

Samy Kacem

Data test strategy and Service Virtualization

Actually I’m digging in different SV (=Service Virtualization) Solution like HP SV, OSV from Tricentis and CA SV. In this context, it allows you to cut from production the real data and play with test data.

What commercial SV can do for you?

  1. Record transactions : You record all the transactions you need for your test scenarios, then the system is playing back all the responses as required.
  2. Scripting the service with a business logic if you need some complex response.
  3. Data driven set : Allows you to fill an Excel spreadsheet or any data container with all the data you require for your test scenarios. Your data set need to be “stateful business process” oriented, that means during the data lifecycle, the object could change state and value.

This last feature will be a good candidate if you are stuck with a legacy or new applications in order to put in place a test data set. The majority of the commercial tools could work with different protocol (http/https, MQ, Filesystem, Ftp/s, etc…). And if the price is a show stopper and you require only http/https, some open source tools are also good candidates. Here you can find a good list of open source and commercial tool.

Samy Kacem