This version is still in development and is not considered stable yet. For the latest stable version, please use spring-cloud-contract 4.1.5!

Stub Runner Spring Cloud

Stub Runner can integrate with Spring Cloud.

For real life examples, see:

Stubbing Service Discovery

The most important feature of Stub Runner Spring Cloud is the fact that it stubs:

  • DiscoveryClient

  • ReactorServiceInstanceLoadBalancer

That means that, regardless of whether you use Zookeeper, Consul, Eureka, or anything else, you do not need that in your tests. We are starting WireMock instances of your dependencies and we are telling your application, whenever you use Feign, to load a balanced RestTemplate or DiscoveryClient directly, to call those stubbed servers instead of calling the real Service Discovery tool.

Test Profiles and Service Discovery

In your integration tests, you typically do not want to call either a discovery service (such as Eureka) or Config Server. That is why you create an additional test configuration in which you want to disable these features.

Due to certain limitations of spring-cloud-commons, to achieve this, you have to disable these properties in a static block such as the following example (for Eureka):

    //Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
    static {
        System.setProperty("eureka.client.enabled", "false");
        System.setProperty("spring.cloud.config.failFast", "false");
    }

Additional Configuration

You can match the artifactId of the stub with the name of your application by using the stubrunner.idsToServiceIds: map.

By default, all service discovery is stubbed. This means that, regardless of whether you have an existing DiscoveryClient, its results are ignored. However, if you want to reuse it, you can set stubrunner.cloud.delegate.enabled to true, and then your existing DiscoveryClient results are merged with the stubbed ones.

The default Maven configuration used by Stub Runner can be tweaked either by setting the following system properties or by setting the corresponding environment variables:

  • maven.repo.local: Path to the custom maven local repository location

  • org.apache.maven.user-settings: Path to custom maven user settings location

  • org.apache.maven.global-settings: Path to maven global settings location