使用 JMS (ActiveMQ) 进行单元测试
如何使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据我的经验(在尝试做同样的事情之后),当您使用 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.
对于简单的集成测试,您可以运行 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.
我正在寻找同样的东西
我用 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.