【发布时间】:2020-08-06 20:13:29
【问题描述】:
我有两个微服务微服务 A(上下文路径 - /abc)和微服务 B(上下文路径 - /def)
示例网址:test.domain.com/abc/endpoint1 ,test.domain.com/def/endpoint2
在微服务 A (test.domain.com/abc/endpoint1) 的其中一个 api 中,它在内部调用微服务 B (/def/endpoint2) -> 此内部调用的前缀生成如下 (从请求中提取域,然后附加 /def/endpoint2 进行休息调用,总 url 将变为(test.domain.com/def/endpoint2)
问题:当我们从控制器级别开始编写单元测试用例时,我们正在使用 TestRestTemplate 对于这个测试,我们需要使用 http://localhost:portnumber/abc/endpoint1 来测试..
现在 def 服务的 url 也将导出为 http://localhost:portnumber/def/endpoint2 如何模拟这个响应(注意:我们不能在同一个端口上使用模拟服务器,我们会得到端口绑定异常)。有没有相同的解决方法?
在使用 TestRestTemplate 路由 http://localhost:portnumber/def/* 调用以获取来自 mockserver 和 http://localhost:portnumber/abc/* 的响应以进行实际测试中的 API 服务?
【问题讨论】:
标签: java unit-testing microservices spring-boot-test mockserver