PACT与Spring Cloud合约测试 [英] PACT vs spring cloud contract tests

查看:259
本文介绍了PACT与Spring Cloud合约测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解PACT和Spring Cloud Contract之间更好的工具,以实施消费者驱动程序合同测试. 我找不到任何明确的例子来找出利弊.

I am trying to understand the better tool between PACT and Spring Cloud Contract to implement Consumer Driver Contract Tests. I dont find any clear examples to find the pros and cons.

我想实现CDCT,并且在我的项目中不使用Spring.根据我的理解,我认为PACT很好.

I want to implement CDCT, and I dont use Spring in my project. From what i understood I am assuming PACT is good to go with.

欢迎任何信息或建议. 谢谢.

Any information or suggestions are welcomed. Thank you.

推荐答案

Spring Cloud Contract允许您为REST API和消息传递定义和测试合同.它提供了清晰易用的静态类型Groovy DSL,还允许通过yaml定义合同.无论是使用DSL还是使用yaml,对于熟悉标准HTTP/消息传递术语的人来说,定义合同都是非常直观的,例如:

Spring Cloud Contract allows you to define and test contracts for both REST APIs and messaging. It provides a clear and easy to use statically typed Groovy DSL and also allows for defining contracts via yaml. Both with the DSL and with yaml, defining contracts is very intuitive to anyone familiar with the standard HTTP/messaging terms, for example:

request {
    method PUT()
    url '/fraudcheck'
    body([
           "client.id": $(regex('[0-9]{10}')),
           loanAmount: 99999
    ])
    headers {
        contentType('application/json')
    }
}
response {
    status OK()
    body([
           fraudCheckStatus: "FRAUD",
           "rejection.reason": "Amount too high"
    ])
    headers {
        contentType applicationJson()
    }
}

生产者端测试由SCC自动生成,并在构建过程中添加到项目中.如果没有正确执行合同的实现,则不会构建和部署该项目.如果它们通过,将生成并发布消费者的存根,并将其与相应的工件版本一起发布.

The producer-side tests are automatically generated by SCC and added to the project during build. If a correct implementation fulfilling the contracts is not in place, the project will not be built and deployed. If they pass, the stubs for consumer will be generated and published along with the corresponding artifact version.

在消费者方面,对于HTTP,SCC提供了Stubrunner,该Stubrunner启动Wiremock(内存中的http服务器)实例,该实例提供对匹配请求的存根响应. Stubrunner可与外部工件存储库(例如Nexus和Artifactory)一起使用,也可与本地m2存储库一起使用.

On the consumer side, for HTTP, SCC provides the Stubrunner, that launches a Wiremock (in-memory http server) instance, that provides stubbed responses to matching requests. Stubrunner works with external artifact repositories such as Nexus and Artifactory and also with local m2 repositories.

SCC与SpringBoot无缝集成,并且还与Spring Cloud集成,可以在集成测试期间代替服务发现.

SCC integrates with SpringBoot seamlessly and also integrates with Spring Cloud out of the box and can be used in place of service discovery during integration tests.

它还与Pact集成在一起,并允许仅使用SCC合同定义时通过钩子利用其他Pact功能.

It also integrates out of the box with Pact and allows to leverage additional Pact features via hooks while using only the SCC contracts definitions.

SCC还提供了一个基于Docker的选项,用于在JVM以外的技术中实施和测试合同.

SCC also provides a Docker-based option for implementing and testing contracts in technologies other than JVM.

免责声明:我是Spring Cloud Contract的提交者.

DISCLAIMER: I’m a Spring Cloud Contract committer.

这篇关于PACT与Spring Cloud合约测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆