eagle icon indicating copy to clipboard operation
eagle copied to clipboard

请问一下 service 层如何测试

Open zoulux opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

这边我看到 dao 层的测试,想知道 svc 怎么测试,有没有示例

zoulux avatar Jun 09 '21 03:06 zoulux

两个办法: 1、把 service 依赖的,比如 dao, 通过使用 mock 给 mock 掉 2、使用 docker-compose 启动依赖的服务,然后对 service 进行测试。 第二个测试起来更真实。

qloog avatar Jun 09 '21 14:06 qloog

方案一 可以提供一些示例进行参考吗,因为还涉及到一些对象的注入 方案二,是不是代价太大,ci 怎么进行落地

zoulux avatar Jun 10 '21 02:06 zoulux

dao 层的测试可以参考:internal/dao/user_follow_dao_test.go

qloog avatar Jun 30 '21 12:06 qloog