如何测试消息队列客户端?

发布于 2024-07-14 04:51:09 字数 413 浏览 4 评论 0原文

我正在开发一个java消息队列客户端(beanstalk),现在我的测试如下所示:

  //make sure our getJob can handle utf8 characters
  @Test
  public void testUTF8() {
    bean = new Beanstalk();
    Job job = new Job();
    bean.putJob("€");
    job = bean.getJob();
    assertEquals("€", job.msg);
    bean.close();
  }

我读到你不应该测试实际的队列本身,因为它不是我编写的代码,但我确实编写了客户端代码 - - 有更好的方法来写这个吗? 我真的需要测试来保证自己,但除了风格之外,为我的 CI 设置也是一件很痛苦的事情。

I am working on a java message queue client (beanstalk) and right now my tests look like this:

  //make sure our getJob can handle utf8 characters
  @Test
  public void testUTF8() {
    bean = new Beanstalk();
    Job job = new Job();
    bean.putJob("€");
    job = bean.getJob();
    assertEquals("€", job.msg);
    bean.close();
  }

I've read that you shouldn't test the actual queue itself cause it's not code that I write but I DO write the client code -- is there a better way to write this? I really need the tests to assure myself but besides style it's also a pain in the ass to setup for my CI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑丑阿 2024-07-21 04:51:09

我不认为编写单元测试来确定/记录外部库的行为有什么问题。 如果您在代码库中包含该测试,那么您就有了队列需要支持 UTF8 的记录; 如果将来改用不同的排队机制,该测试就会中断并需要重写,迫使新排队机制的实现者考虑新系统是否也可以处理UTF8。 在我看来,这是一件好事。

至于在 CI 中进行设置,我的建议是,将其分类为集成测试,并在安装了队列支持(如果有的话)的 CI 机器上运行它。

I don't think there's anything wrong with writing unit tests to determine/document the behavior of an external library. If you include that test in your code base, then you have a record of the fact that your queue needs to support UTF8; if you change to a different queueing mechanism in the future, that test will break and need to be rewritten, forcing the implementer of the new queueing mechanism to consider whether the new system can also handle UTF8. That's a good thing, in my opinion.

As for setting this up in your CI, my suggestion is that you classify this as an integration test and run it on a CI machine that has queueing support installed, if you have one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文