W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在您不想執(zhí)行“消費者合同”方法(為每個消費者定義期望)但您更愿意使用“生產(chǎn)者Contracts”(生產(chǎn)者提供合同并發(fā)??布存根)的情況下,足夠使用Spring Cloud Contract和Stub Runner選項。可以在此處找到此類設(shè)置的示例。
首先,請記住添加Stub Runner和Spring Cloud Contract Pact模塊作為測試依賴項。
Maven.
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Don't forget to add spring-cloud-contract-pact to the classpath! --> <dependencies> <!-- ... --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-contract-stub-runner</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-pact</artifactId> <scope>test</scope> </dependency> </dependencies>
Gradle.
dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } dependencies { //... testCompile("org.springframework.cloud:spring-cloud-starter-contract-stub-runner") // Don't forget to add spring-cloud-contract-pact to the classpath! testCompile("org.springframework.cloud:spring-cloud-contract-pact") }
接下來,只需將Pact Broker的URL傳遞到以pact://
協(xié)議為前綴的repositoryRoot
。例如pact://http://localhost:8085
@RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.REMOTE, ids = "com.example:beer-api-producer-pact", repositoryRoot = "pact://http://localhost:8085") public class BeerControllerTest { //Inject the port of the running stub @StubRunnerPort("beer-api-producer-pact") int producerPort; //... }
通過這樣的設(shè)置:
有關(guān)Pact支持的更多信息,請轉(zhuǎn)至“使用Pact存根下載器”部分。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: