Key concepts
These are the core concepts that form the basis of the Hoverfly Cloud API simulation platform
Overview
To get started Hoverfly Cloud, you need to understand a few concepts: Services, Scenarios, Simulations and Behaviors.
Services
Hoverfly Cloud services simulates real HTTP services such as web APIs and SOAP services. You can think of Hoverfly Cloud services as API simulations, over the wire test doubles, or more highly configurable HTTP stubs and mocks.
Hoverfly Cloud uses our Open Source tool, Hoverfly to simulate a service. Hoverfly Cloud uses Kubernetes to run and manage multiple copies of Hoverfly, and adds a powerful GUI with many additional capabilities.
A service is a physical running instance of Hoverfly, and it is configured with a Simulation file as described below.
Simulations
If you have used Hoverfly you will know that it captures the interactions of a HTTP service in a simulation file.
Simulations are JSON files that contains pairs of HTTP requests and their corresponding HTTP responses, also known as request/response pairs.
You can also create simulations in Hoverfly Cloud. If you have an account you can see yours on the Simulations page here. Hoverfly Cloud also allows you to create simulations from Swagger Specifications.
The simulation file, once created, defines what the API simulation will look like and how it will respond to requests. You load the simulation file into a Hoverfly service in order to have a real running API Simulation.
Simulations can be configured in many ways. They can serve up static responses, or they can use templating using handlebars syntax to create powerful, flexible responses using logic, arithmetic, looping and state.
A simulation file is made up of request/response pairs. Each pair contains request matchers which are rules governing how the simulation will match an incoming request. For example you can configure a matcher to look for a specific path structure, or header, or some JSON in the body. The associated response is what Hoverfly will send back to the caller, once a request has been matched, and includes the response body, status code and headers.
Behaviors
Behaviors allow you to change a simulation quickly, for instance making your service simulation badly behaved except in a predictable way which is what you need for testing!
Behaviors are intended to create specific conditions to support testing. A wide range of behaviors is supported including HTTP header errors, data errors, latency simulations and more. This is very useful for understanding how your application behaves under stress or in unpredictable production environments. We recently had a case where customers were struggling to reproduce a problem seen in production in their test environment. Using Hoverfly Cloud they quickly replicated the problem using behaviors and fixed the problem.
A Scenario
You can use a Hoverfly Cloud scenario to model a business scenario, for example modelling a payment gateway where all services are working normally, or conversely a flaky third-party API that intermittently fails. A mobile banking app could then be tested to ensure it could handle all these situations appropriately.
Scenarios can be combined with behaviors. A 'business as normal scenario' can be reconfigured with behaviors to predictably inject a variety of errors, for instance retail application could have a Black Friday scenario where there is adverse network latency.
A scenario can consist of a collection of services. For example, suppose you are testing an application to support mortgage approvals. A scenario would define multiple services such as the Land Registry to validate the property reference, postcode validation, customer validation, credit checks, and so on. This complex data-rich set of services would change each time you change and test your application. You would be forced to manually test your application. Using a Hoverfly scenario you could capture the multiple interactions with services and allow the test to be automated.
A scenario describes multiple services and their configuration data and can be started in seconds.
The Hoverfly Cloud CLI (hcc)
The Hoverfly Cloud command line tool (hcc) can be used to:
Create simulations locally by capturing and exporting traffic between a client and an API
Upload simulations to Hoverfly Cloud
Start and stop remote Hoverfly Cloud services and scenarios
Provide a local reverse proxy server for accessing an authenticated Hoverfly Cloud service.
The Hoverfly Cloud CLI requires an API token to authenticate with Hoverfly Cloud. It can be installed on development machines or continuous integration servers.
Last updated