为 Kafka Spring 编写集成测试还是单元测试更好?
我一直在寻找在 Spring 中测试 Kafka 的最佳方法。 据我所知,@EmbeddedKafka更多的是用于单元测试,但是通过为其编写集成测试来在真实的工作环境中测试Kafka不是更好吗? 我通过为 Kafka 编写单元测试到底是在测试什么? 一个真正工作的生产者和消费者应该比嘲笑kafka更有意义。 你有什么建议?
I've been searching a while about the best way to test Kafka in Spring.
As far as I know, @EmbeddedKafka is more for an unit test but isn't it better to test Kafka in a real working environment by writing integration test for it?
And what really am I testing by writing unit test for Kafka?
A real working producer and consumer should be more meaningful than mocking the kafka.
What do you suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EmbeddedKafka
是集成测试。它启动一个真正的经纪人,而不是一个模拟经纪人,供您与之交互。对于单元测试,Kafka 为消费者和生产者提供自己的模拟,不依赖于 Spring 库
你的一般处理逻辑,包括错误处理和反序列化
在 Kafka Streams 中,你还可以根据模拟窗口来控制记录的时间来测试聚合逻辑
EmbeddedKafka
is an integration test. It starts a real broker, not a mock, for you to interact with.For unit testing, Kafka provides its own mocks for consumer and producer, not reliant on Spring libraries
Your general processing logic, including error handling and deserialization
In Kafka Streams, you can also control the timing of the records for testing aggregation logic based on simulated windows