I am involved in Projects involving EJBs and I have always faced problems about testing EJBs. Can anyone suggest a resource or other postings on this website that tries to streamline Testing of EJBs. In short How do I test my EJBs.
We looked into cactus (extension to junit) a bit but decided to stick with our current solution: junit tests.
The setup we have:
- jboss and weblogic test servers with hot-deploy on.
- build enterprise archives with ant for the 2 appservers
- copy to deploy dirs (also with ant)
- load jndi properties for the servers
- run the junit tests (also from ant)
it requires some work in setting up all the ant scripts but it works quite well I think..
Consider writing your own test code to simulate the
EJB container. I have done this for two different
projects now with good results.
In short you would:
a) Create your own Context which is obtained when you
do lookup. Check out InitialContextFactoryBuilder
b) Have this Context create objects implementing the
Home interface. Check the java.lang.reflect.Proxy
class for doing this on the fly. Calls should be
forwarded to the correct implementation in your bean
c) Create objects implementing the EJBObject interface
using the same technic as when Home objects are called.
Make sure to call all life-cycle method upon creation
All in all this will give you a test framework for running
your beans without the container. You can then run tests
from any IDE without deployment. Of course you cannot test
everything this way, but I find that it helps a lot that
you can test dependancies between EJBs without the container.