Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing with JMS (ActiveMQ)

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 ?

like image 418
Larry Cai Avatar asked May 20 '10 01:05

Larry Cai


People also ask

Does ActiveMQ support JMS?

Apache ActiveMQ Artemis supports the direct instantiation of JMS Queue, Topic and ConnectionFactory instances, so you don't have to use JNDI at all.

What is difference between JMS and ActiveMQ?

What Is the Difference Between JMS and ActiveMQ? ActiveMQ is a JMS provider. A JMS provider forms the software framework for facilitating the use of JMS concepts inside an application. A single node of ActiveMQ which allows clients to connect to it and use these messaging concepts is called an “ActiveMQ Broker.”

What is Artemis MQ?

Apache ActiveMQ Artemis is an asynchronous messaging system, an example of Message Oriented Middleware , we'll just call them messaging systems in the remainder of this book.


2 Answers

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.

like image 101
kellyfj Avatar answered Sep 17 '22 12:09

kellyfj


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.

like image 31
mjn Avatar answered Sep 18 '22 12:09

mjn