Spring 不同环境测试的云合约

Spring cloud contract for different environments testing

我的客户要求我提出关于 Spring 云合同的 POC,因为我们将在全球项目中使用这个框架。我也遵循了在线可用的示例和文档。但是,我有几个问题。

  1. 如果应用程序托管在 DEV、STAG、PROD 等不同环境中..我们是否需要为所有这三种环境生成存根?

  2. 有没有办法使用 gradle 脚本将存根存储到存储库?以便我可以将存根从存储库下载到我的本地测试环境并进行测试?

抱歉,我对这个框架还很陌生,非常感谢您的回答。 如果可能,请提供一些上述示例。

提前致谢

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

这取决于您的部署策略,但总的来说,我不这么认为。您可以在 Spring Cloud Pipelines 项目 - http://cloud.spring.io/spring-cloud-pipelines/single/spring-cloud-pipelines.html#_opinionated_implementation 中查看我的基本原理。如果你想进行持续交付,你应该为当前构建的版本创建存根。该版本将通过一个部署管道,该管道将通过阶段和生产。

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?

您可以使用类路径扫描 - 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。这是一个 Maven 构建,但我相信无论如何你都能理解这个想法(这个例子在 Eureka 中注册存根并将消息发送到一个真正的 RabbitMQ 实例,当然,如果你不需要它们,你可以删除这些功能)。