How to create unit tests for EJB 3.0 based code to be deployed in jboss 5.1?
Greetings,
I am interested in adding test coverage for an existing application. The technologies involved include EJB 3.0, jboss 5.1, Hibernate and MySQL. This project is built using Ant. The goal is to provide test coverage to this application to allow further features to be added with confidence.
Initial searches give several ideas, but I have yet to find an tutorial or a start to finish set up steps to create an initial uni开发者_Python百科t test.
I found EJB3Unit to be promising. http://ejb3unit.sourceforge.net/Installation.html
However, the examples to setup are for maven and we are using Ant.
If anyone could help with how to setup a simple example test with EJB3Unit and Ant it would be very helpful.
Thanks for your time,
Conor
You will have to ask yourself "What exactly am I trying to test?" first.
If you want to test your EJB3 in isolation, remember that an EJB3 is just a POJO. You can call the class directly from a jUnit test method.
If you want to test your EJB, the Application server, the Container, AND your network (if @Remote annotation is used) then you can write an integration test class that looks up the @Remote or @Local EJB in the JNDI tree of your container like so:
@Test
public void callEjb() throws Exception {
Context context = new InitialContext();
YOUR_EJB_CLASS myEjb = (YOUR_EJB_CLASS) context
.lookup(JNDI_PATH_FOR_YOUR_EJB);
myEjb.myMethod();
}
If you want to test your EJB as an EJB and separate from an EJB Container, then EJB3 could be what you are looking for instead.
P.S. Don't let Maven scare you. I haven't used it yet, but it seems that it is gaining in mind-share over ant.
精彩评论