SpringCloud 客戶端

2023-12-06 17:06 更新

Spring Cloud Contract生成存根,可在客戶端測(cè)試期間使用。您將獲得一個(gè)正在運(yùn)行的WireMock實(shí)例/消息傳遞路由,以模擬該服務(wù)。您想使用適當(dāng)?shù)拇娓x來(lái)提供該實(shí)例。

在某個(gè)時(shí)間點(diǎn),您需要向欺詐檢測(cè)服務(wù)發(fā)送請(qǐng)求。

ResponseEntity<FraudServiceResponse> response = restTemplate.exchange(
		"http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
		new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);

用?@AutoConfigureStubRunner?注釋測(cè)試類。在批注中,提供Stub Runner的組ID和工件ID,以下載協(xié)作者的存根。

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {
		"com.example:http-server-dsl:+:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL)
public class LoanApplicationServiceTests {

之后,在測(cè)試期間,Spring Cloud Contract在Maven存儲(chǔ)庫(kù)中自動(dòng)找到存根(模擬真實(shí)服務(wù)),并將其暴露在已配置(或隨機(jī))的端口上。


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)