Search code examples
spring-cloud-contract

Spring cloud contract for different environments testing


My client has asked me to come out with a POC on Spring cloud contract as we are going to use this framework across global projects. I have followed the examples available online and documentation as well. However, I am having few questions.

  1. if application hosted in different environments like DEV,STAG,PROD ..do we need to generate the stubs for all these three environments?

  2. Is there way to store stubs to a repository using gradle script? So that I can download the stub to my local test environment from repository and test?

Sorry, I am very new to this framework and very much thankful for your answers. If possible, please provide some samples for the above.

Thanks in advance


Solution

  • if application hosted in different environments like DEV,STAG,PROD ..do we need to generate the stubs for all these three environments?

    It depends on your deployment strategy but in general, I don't think so. You can check my rationale in Spring Cloud Pipelines project - http://cloud.spring.io/spring-cloud-pipelines/single/spring-cloud-pipelines.html#_opinionated_implementation . If you want to do continuous delivery you just should create stubs for the current built version. That version will go through a deployment pipeline that would go via stage and prod.

    Is there way to store stubs to a repository using gradle script? So that I can download the stub to my local test environment from repository and test?

    You can use the classpath scanning - http://cloud.spring.io/spring-cloud-static/Dalston.SR4/multi/multi__spring_cloud_contract_stub_runner.html#_classpath_scanning . That way you set your Gradle build in such a way that you have the stubs on classpath. If you're referring to downloading a stub to run it inside a seprate proces you can combine this with Stub Runner Boot. Example is available here - https://github.com/spring-cloud-samples/github-analytics-stub-runner-boot-classpath-stubs/blob/master/pom.xml#L77-L88 . It's a Maven build but I'm sure that you get the idea regardless (this example registers stubs in Eureka and sends messages to a real RabbitMQ instance, of course you can remove these features if you don't need them).