W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Stub Runner Spring Cloud
的最重要特征是它正在存根
DiscoveryClient
Ribbon
ServerList
這意味著無(wú)論您使用的是Zookeeper,Consul,Eureka還是其他任何東西,您都不需要在測(cè)試中使用它。我們正在啟動(dòng)依賴(lài)項(xiàng)的WireMock實(shí)例,并且在您每次使用Feign
,直接負(fù)載均衡RestTemplate
或DiscoveryClient
來(lái)調(diào)用那些存根服務(wù)器而不是調(diào)用真實(shí)服務(wù)時(shí),都告訴您的應(yīng)用程序發(fā)現(xiàn)工具。
例如,該測(cè)試將通過(guò)
def 'should make service discovery work'() { expect: 'WireMocks are running' "${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' "${stubFinder.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' and: 'Stubs can be reached via load service discovery' restTemplate.getForObject('http://loanIssuance/name', String) == 'loanIssuance' restTemplate.getForObject('http://someNameThatShouldMapFraudDetectionServer/name', String) == 'fraudDetectionServer' }
對(duì)于以下配置文件
stubrunner: idsToServiceIds: ivyNotation: someValueInsideYourCode fraudDetectionServer: someNameThatShouldMapFraudDetectionServer
在集成測(cè)試中,您通常既不想調(diào)用發(fā)現(xiàn)服務(wù)(例如Eureka)也不能調(diào)用Config Server。這就是為什么您要?jiǎng)?chuàng)建其他測(cè)試配置以禁用這些功能的原因。
由于spring-cloud-commons
達(dá)到此目的的某些限制,您已通過(guò)如下所示的靜態(tài)塊(Eureka的示例)禁用了這些屬性
//Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156 static { System.setProperty("eureka.client.enabled", "false"); System.setProperty("spring.cloud.config.failFast", "false"); }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: