使用 JMS (ActiveMQ) 进行单元测试

发布于 2024-09-02 08:11:17 字数 332 浏览 2 评论 0原文

如何使用JMS进行单元测试?这是事实上的吗?

我用谷歌搜索了一些东西 - JMS 单元测试:http://activemq.apache.org /how-to-unit-test-jms-code.html - jmsTemplate:activemq.apache.org/jmstemplate-gotchas.html -mockRunner:mockrunner.sourceforge.net/

您对这些有什么好的经验和建议吗?

How to do unit testing with JMS ? Is it some de-facto for this ?

I googled something
- Unit testing for JMS: http://activemq.apache.org/how-to-unit-test-jms-code.html
- jmsTemplate: activemq.apache.org/jmstemplate-gotchas.html
- mockRunner : mockrunner.sourceforge.net/

Do you have any good experience on those and suggestion for me ?

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

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

发布评论

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

评论(3

双马尾 2024-09-09 08:11:17

根据我的经验(在尝试做同样的事情之后),当您使用 JMS 时,您正在执行类似

1) 获取 JMS 消息的操作
2) 从消息中提取对象
3)用对象做一些事情

从这个角度来看,我建议你进行单元测试#3,但不要打扰单元测试#1或#2 - 不要测试框架 - 专注于测试你的代码。我认为(单元)测试您的基础设施(类似 EJB 基础设施等)没有什么好处。类似的事情最好留给集成/系统测试。

In my experience (after trying to do the same thing) when you are using JMS you are doing something like

1) Get JMS Message
2) Extract Object from Message
3) Do something with Object

From that point of view I would suggest you unit test #3 but don't bother unit testing #1 or #2 -- don't test the framework -- focus on testing your code. I think it's of little benefit to (unit) test your infrastructure (similarly EJB infrastructure etc.). Things like that are better left to integration / system testing.

蓝咒 2024-09-09 08:11:17

对于简单的集成测试,您可以运行 ActiveMQ嵌入式模式下的代理。使用 Maven,这可以自动化,因此您甚至不必下载和安装 ActiveMQ 消息代理。

For simple integration tests you can run the ActiveMQ broker in embedded mode. With Maven, this can be automated so you do not even have to download and install the ActiveMQ message broker.

风透绣罗衣 2024-09-09 08:11:17

我正在寻找同样的东西
我用 JMock 做过一次,用它你可以测试消息创建,并与 hamcrest 结合你可以实现很好的事情。

i looking for same kind of thing
I've done it once with JMock, with it ypu can test the message creattion and combined with hamcrest you can achieve nice things.

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