Category Archives: Testing
Java EE Unit Testing Made Easier
The concept of unit testing has been around for some time and is considered a good practice for all developers. Frameworks for unit testing abound in the Java EE landscape, including such options as JUnit and TestNG. These and other frameworks are best utilized with POJOs, in which functionality to be tested can be isolated to a single method. This even works for complex, heavy-duty “algorithmic” methods because, ultimately, these methods can are isolated to a single class (if the principle of encapsulation is closely followed) and are independent of external resources such as EJBs, JMS, or database calls.
However, leveraging the full power of Java EE generally necessitates use of container-managed or other external objects with complex dependencies (e.g. EJBContext or JPA), making unit testing a difficult practice to follow. “Microcontainer” options are available and include products such as GlassFish and JBoss, but setting these up can be prohibitively cumbersome and platform dependent – GlassFish and JBoss microcontainers require Oracle and JBoss target environments, respectively.
After numerous frustrating attempts at performing EJB unit tests with TentNG and JUnit, there appear to be new developments on the horizon that will make this task much more simple. Arquillian is a new testing framework (currently in Alpha) designed to make the testing of EJB/JPA objects as straightforward and flexible as testing options for POJOs. Here’s to hoping this new framework makes life a little easier for us all.
