如何在Kafka go中编写单元测试

huangapple go评论70阅读模式
英文:

How to write unit tests in Kafka go

问题

在golang中编写Kafka的单元测试的正确方法是什么?

在Java中,对于Kafka流,我们有Kafka流测试工具,它简化了编写测试用例的过程。

然而,我在golang中找不到类似的东西。

有一些很好的文章介绍如何使用Docker容器启动Kafka并测试端到端的流程。但我真正想要的是带有模拟服务器的单元测试。

我正在使用confluent kafka go。

英文:

What is the correct way to write unit tests for Kafka in golang?

In java, for Kafka streams we have Kafka stream test until that simplifies writing test cases.

However, I am not able to find similar things in Kafka for golang.

There are a few nice articles on how to use docker containers to bring up Kafka and test the E2E flow. But I am really looking for unit tests with mock servers.

I am using confluent kafka go

答案1

得分: 0

你要翻译的内容如下:

不清楚你正在寻找哪个库。Sarama有一个可以使用的模拟包https://github.com/Shopify/sarama/tree/main/mocks

你不需要模拟服务器,只需要模拟客户端之间的数据传递。

英文:

Unclear what library you're looking for. Sarama has a mocks package that can be used https://github.com/Shopify/sarama/tree/main/mocks

You don't mock servers, only data passing between clients

huangapple
  • 本文由 发表于 2021年12月24日 03:07:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/70466433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定