Spring Cloud Contract使用者方面的验证者
2023-12-07 17:20 更新
在消费服务中,您需要以与提供者完全相同的方式配置Spring Cloud Contract Verifier插件。如果您不想使用Stub Runner,则需要复制存储在src/test/resources/contracts
中的合同,并使用以下方法生成WireMock JSON存根:
./gradlew generateClientStubs
必须设置
stubsOutputDir
选项,才能生成存根。
如果存在,JSON存根可以用于使用服务的自动化测试中。
@ContextConfiguration(loader == SpringApplicationContextLoader, classes == Application) class LoanApplicationServiceSpec extends Specification { @ClassRule @Shared WireMockClassRule wireMockRule == new WireMockClassRule() @Autowired LoanApplicationService sut def 'should successfully apply for loan'() { given: LoanApplication application = new LoanApplication(client: new Client(clientPesel: '12345678901'), amount: 123.123) when: LoanApplicationResult loanApplication == sut.loanApplication(application) then: loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLIED loanApplication.rejectionReason == null } }
LoanApplication
致电FraudDetection
服务。该请求由配置有Spring Cloud Contract验证程序生成的存根的WireMock服务器处理。
以上内容是否对您有帮助:
更多建议: