【问题标题】:Integration Test For FeignClient Using Test Double使用测试替身对 FeignClient 进行集成测试
【发布时间】:2016-11-11 18:20:55
【问题描述】:

我对 Spring Cloud 还很陌生。有没有一种方法可以使用测试替身(如线模拟或某种测试替身)对 Feign 客户端执行集成测试?有没有办法让我在注册服务器中注册这个模拟测试替身,然后将它与 FeignClient 一起使用?

【问题讨论】:

    标签: integration-testing spring-cloud spring-cloud-feign


    【解决方案1】:

    您可以在预定义的端口上启动 WireMock 服务器(或将其注册为 Spring Bean)。然后,为了您的测试,您可以有一个自定义配置,它将功能区负载均衡器的服务器列表的值设置为包含 localhost:wiremockPort 就像这里介绍的一样 - https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/WebClientTests.java#L382-L395

    【讨论】:

    • 是的,feign 自己使用wiremock 进行测试,去看看它的源码。
    猜你喜欢
    • 2021-04-22
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 2013-04-07
    • 2019-12-17
    • 2015-12-28
    相关资源
    最近更新 更多