How to create unit tests for EJB 3.0-based code for deployment in jboss 5.1?

Greetings

I am interested in adding test coverage for an existing application. 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 for this application to add additional features with confidence.

Initial searches give a few ideas, but I still have to find a tutorial or start preparing steps to create an initial unit test.

I found EJB3Unit promising. http://ejb3unit.sourceforge.net/Installation.html

However, setup examples for maven and we use Ant.

If someone can help with setting up a simple test example with EJB3Unit and Ant, this will be very helpful.

Thank you for your time,

Conor

+3
source share
1 answer

You need to ask yourself: "What exactly am I trying to verify?" the first.

If you want to test your EJB3 separately, remember that EJB3 is just a POJO. You can call the class directly from the jUnit testing method.

If you want to test your EJB, application server, container and your network (if @Remote annotation is used), you can write an integration test class that looks for @Remote or @Local EJB in the JNDI tree of your container:

@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 EJB as an EJB and separate from the EJB Container, then EJB3 may be what you are looking for.

P.S. Maven . , , ant.

0

All Articles