I wish to know about the right approach for testing JMS in my Spring application using JUnit. The JMS resources are being injected in the config XML file using JNDI. Obviously, this cannot be used by JUnit as the objects are bound with the application server (Websphere). With this config file in place, I am not even able to run my other test cases in the application which have nothing to do with JMS. I get BeanCreationException because of NoClassDefFoundError for com.ibm.webspere.naming.WsnInitialContextFactory.
So, if any one can point me to a tutorial or document which would help me with this, I would be grateful.
If you're trying to test JMS code, you have to run something JMS-aware.
If you're trying to test code separate from JMS, then you need to configure your environment more granularly. I always try to make a distinction between my code that uses JMS as a transport mechanism, and JMS itself: I'm not trying to test the underlying JMS implementation, I'm almost always trying to test my code that happens to use JMS.
For testing JMS without using the server, This is what we did in one of our applications (with Weblogic, But i believe it should work fine for Websphere as well).
Instead of using server specific objects in application try using classes provided by spring:
define Your message sender which will have a JmsTemplate that you can use to send messages like this:
Define the jndiTemplate
and the jms factory:
Now you can just pass the connectionFactory and the jndiname of the JMS Q and initiate the beans which are not dependent on the server.
PS: you will have to use some JMS API for creating the Q's in developement mode... We used ActiveMQ to create the Q's while running tests... On production mode that will be available on the server where the application is deployed...