https://circleci.com/gh/SpectoLabs/hoverfly-java.svg?style=shield https://readthedocs.org/projects/hoverfly-java/badge/?version=latest https://codecov.io/gh/spectolabs/hoverfly-java/branch/master/graph/badge.svg https://img.shields.io/maven-central/v/io.specto/hoverfly-java.svg

What is Hoverfly Java?

Hoverfly is a lightweight service virtualisation tool which allows you to stub / simulate HTTP(S) services. It is a proxy written in Go which responds to HTTP(S) requests with stored responses, pretending to be it’s real counterpart.

It enables you to get around common testing problems caused by external dependencies, such as non-deterministic data, flakiness, not yet implemented API’s, licensing fees, slow tests and more.

Hoverfly Java is a native language binding which gives you an expressive API for managing Hoverfly in Java. It gives you a Hoverfly class which abstracts away the binary and API calls, a DSL for creating simulations, and a JUnit integration for using it within JUnit tests.

Hoverfly Java is developed and maintained by SpectoLabs.



If using Maven, add the following dependency to your pom:



Or with Gradle add the dependency to your *.gradle file:

testCompile "io.specto:hoverfly-java:0.4.3"

Code example

The simplest way is to get started is with the JUnit rule. Behind the scenes the JVM proxy settings will be configured to use the managed Hoverfly process, so you can just make requests as normal, only this time Hoverfly will respond instead of the real service (assuming your HTTP client respects JVM proxy settings):

public class HoverflyExample {

    public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode(dsl(
            .willReturn(success("{\"bookingId\":\"1\"}", "application/json"))

    public void shouldBeAbleToGetABookingUsingHoverfly() {
        // When
        final ResponseEntity<String> getBookingResponse = restTemplate.getForEntity("http://www.my-test.com/api/bookings/1", String.class);

        // Then

// Continues...