Skip to content

Service virtualization in testing: when a dependent system is unavailable

B2Bnetwork team · · 6 min

IT in banking

In brief

Service virtualization means replacing a dependent system in testing with a program that responds like that system: to the same requests, in the same format, with realistic latency and errors. You use it when the real system is unavailable, charges per call, has no test environment, or cannot be made to produce rare cases. It works well when the virtual service is held to a contract with the real system and the final pre-release test still goes through the real connection.

When a dependent system blocks testing

In a bank, almost every process touches a system the team does not control. Typical cases:

  • the credit bureau or other registers: a test environment with a limited number of queries and a fixed set of test customers,
  • the clearing house and card schemes: test windows booked in advance, messages in industry formats,
  • the identity verification provider: a charge for every call, even in the test environment,
  • a mainframe core system: one shared test environment that does not respond for several hours during deployments,
  • another team's system still under construction: the API does not exist yet, but the contract is agreed.

Without a stand-in, the lending process test waits for the credit bureau, the payment test waits for a clearing house window and the mobile app team waits for the core. Service virtualization cuts these dependencies at the stages where they are not what is being tested.

Stub, mock and virtual service

These terms are often confused, but they differ in scope and in who uses them.

TermWhere it runsWhat it can doTypical use
stubin code or as a simple servera fixed response to a requestunit tests, early development
mockin the test codechecks whether a call happened and with which parametersunit and component tests
virtual servicea separate network process shared by many teamsdata-dependent responses, state, latency, errors, several protocolsintegration, system and performance tests

A virtual service sits at the same address where the application expects the real system. The application does not know it is talking to a simulator, so the test exercises the real connection configuration, serialization and error handling.

How to build a virtual service

There are two approaches, and they are usually combined.

Recording. A tool sits between the application and the real system in a test environment, captures request and response pairs, and then replays them. It is a fast start, but a recording only shows what happened to pass through the connection. Rare responses have to be added by hand, and the data in recordings must be checked for personal data.

Modeling from a contract. The service is built from a specification: OpenAPI, AsyncAPI, WSDL or a file format description. Responses depend on the request data according to rules, for example "a national ID number ending in 13 returns a history with a late payment". This gives full control over edge cases.

A good virtual service in a bank can do four things that simple stubs cannot:

  1. State. After a card is blocked, the next query returns a blocked card. This requires memory between calls or state scenarios.
  2. Latency. A response after 50 ms and one after 8 s are two different tests. The virtual service reproduces the production response time distribution and timeouts.
  3. Errors. A rejection with a business code, a technical error, a dropped connection, a response that violates the schema. In a real test environment these cases usually cannot be triggered on demand.
  4. Control from the test. The test sets what the service should answer before running, for example through an admin API, instead of relying on magic data.

Tools

ToolLicenseStrengths
WireMockopen sourceHTTP, record and playback, state scenarios, control via API
Hoverflyopen sourceworks as a proxy, traffic capture, latency simulation
Microcksopen sourcevirtual services from OpenAPI and AsyncAPI contracts, including events
commercial service virtualization toolspaidmany protocols (MQ, mainframe, binary formats), management for a large organization

For REST and events, open source tools are usually enough. For MQ queues, core transactions and binary card system formats, the choice depends on whether the tool supports the protocol or you have to write your own adapter. A simulator written in code is sometimes simpler than bending a tool when the protocol is unusual.

The risk: a virtual service that lies

A virtual service is trustworthy only as long as it responds like the real system. When the vendor adds a field or changes an error code, tests keep passing green while production breaks. Three safeguards:

  • Contract tests check both the application against the virtual service and the real system against the same contract. The principles are covered in API contract testing.
  • Periodic comparison with the real system: the same requests sent to the virtual service and to the partner's test environment, with differences in a report.
  • A final test over the real connection before release, in a booked partner window. Virtualization shortens the road to this test but does not replace it.

Virtual services also need to be maintained like code: in a repository, versioned in line with the contract versions, and with an owner. A shared catalog of virtual services in the SIT environment saves work for the next teams. How they fit into environment organization is covered in Test environments in a bank, and how they fit into an automation plan in Test automation in banking.

B2Bnetwork engineers build virtual services of dependent systems as part of test automation in banks and in manufacturing, where they replace even machines. The scope is described on the Test automation page, and an example with virtual machines is shown in this case study.

Questions and answers

Does service virtualization replace the partner's test environment?

No. It shortens the road to a test over the real connection and lets you test cases the partner cannot trigger. Before release, the process still goes through a final test in the partner's environment, because only that confirms certificates, network configuration and the current interface version.

How much work does the first virtual service take?

For a REST API with an OpenAPI contract, the first responses usually work within a day. Adding state, latency, errors and test control takes from a few days to a few weeks, depending on the number of operations. Binary formats and queues that the tool does not support out of the box take the most work.

Can virtual services be used in performance testing?

Yes, and often they have to be, because a partner will not agree to a load test of its environment. The virtual service must then handle the traffic itself and reproduce realistic response times. The result shows the performance of the bank's systems, not the partner's, and the report should say so.

Can traffic recordings contain personal data?

They can, if you record traffic in an environment with a copy of customer data. The recordings must then be masked before they are stored in a repository, or recorded only on synthetic data. The delegated regulation under DORA (the EU Digital Operational Resilience Act) limits production data in non-production environments, and the GDPR applies to test files too.

What it looks like in a project

Working on banking systems? Talk to an engineer who knows their constraints.

Let's talk

Read more: IT in banking

All in IT in banking →