简体   繁体   English

Spring Cloud Contract 测试是否应该实际调用外部服务?

[英]Should Spring Cloud Contract tests actually call an external service?

I'm having trouble finding out the answer to this..我很难找到这个问题的答案..

I'm exposing an endpoint, JSON data is being sent to it.我正在公开一个端点,JSON 数据正在发送给它。

Inside my service I'm then mapping this to a POJO, serialising to a JSON request, then firing that on to my service via OpenFeign (internal service within company).在我的服务中,我将其映射到 POJO,序列化为 JSON 请求,然后通过 OpenFeign(公司内部服务)将其发送到我的服务。

Should I be mocking everything in terms of the response?就响应而言,我应该是 mocking 吗? Or are contract tests meant to test this integration?或者合同测试是为了测试这种集成?

Currently I am analysing the actual response from the service I'm calling.目前我正在分析我正在调用的服务的实际响应。

On the producer side, your controller should have all the services mocked.在生产者方面,您的 controller 应该模拟所有服务。 It means that it will not call a database nor another service to get back the response.这意味着它不会调用数据库或其他服务来获取响应。 What you should do is to create a simple controller object and inject fake / mocked services that will return fixed responses.您应该做的是创建一个简单的 controller object 并注入将返回固定响应的虚假/模拟服务。 Contract tests are about checking if you can communicate, not about checking if the functionality is working fine.合同测试是关于检查您是否可以沟通,而不是检查功能是否正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成的测试在Spring Cloud Contract中失败 - Generated tests fail in Spring Cloud Contract 使用spring-cloud-contract-oa3和spring cloud contract gradle插件时无法生成合约测试 - Unable to generate contract tests when using spring-cloud-contract-oa3 and spring cloud contract gradle plugin 如何在 spring-cloud-gateway 合约测试中从 spring-cloud-contract 中设置带有 StubRunner 端口的 url - How to set urls with port of StubRunner from spring-cloud-contract in spring-cloud-gateway contract tests Spring Cloud Contract 测试适用于 Maven,但不适用于 JUnit - Spring Cloud Contract tests work with Maven but not when run with JUnit Spring Cloud合约测试的在线/离线模式存在问题 - Problems with the online / offline mode of the Spring Cloud contract tests 我们是否需要在Spring Cloud Contract中存根其他微服务 - Do we need to stub the other micro service in Spring cloud contract 如何在 Spring Cloud 合同的生产者上模拟控制器中的服务 - how to mock the service in controller on producer for spring cloud contract 如何在Spring Cloud Contract存根上获取服务状态 - How to get service state on spring cloud contract stub 如何在不构建项目中的所有单元和合同测试的情况下生成和运行单个合同测试? Java Spring Cloud 合约验证器 - How to generate and run a single contract test without building all the unit and contract tests in the project? Java Spring Cloud Contract Verifier 无法将 RestAssured 的 RQ/RS of Spring Cloud Contract 的测试附加到 Allure 报告 - Can't attach RestAssured's RQ/RS of Spring Cloud Contract's tests to Allure report
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM