使用JMS(ActiveMQ)进行单元测试 [英] Unit testing with JMS (ActiveMQ)
问题描述
如何使用JMS进行单元测试?这是事实吗?
我用Google搜索了一些东西 -JMS的单元测试: http://activemq.apache.org /how-to-unit-test-jms-code.html -jmsTemplate:activemq.apache.org/jmstemplate-gotchas.html -mockRunner:mockrunner.sourceforge.net/
您在这些方面有什么很好的经验以及对我的建议吗?
以我的经验(尝试做同样的事情),当您使用JMS时,您正在做类似的事情
1)获取JMS消息 2)从消息中提取对象 3)对对象做某事
从这个角度来看,我建议您进行单元测试3,但不要打扰单元测试1或2,不要测试框架,而是专注于测试代码.我认为(单元)测试基础结构(类似EJB基础结构等)几乎没有什么好处.这样的事情最好留给集成/系统测试.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 ?
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.
这篇关于使用JMS(ActiveMQ)进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!