Which online resources, tutorials or books can you recommended to get started with unit testing J2EE / EJB3 applications?
So far I have found ejb3unit, Jakarta Cactus (retired 2011/08) and the Maven Cargo plugin. It would be helpful if there are complete working examples, ready to run.
Target containers are the open source products GlassFish, JBoss and Apache OpenEJB.
The simplest way to unit test Java EE components is to use plain JUnit without any special runner and Mockito to mock away every other involved component. @Stateless public class TaskStore { @PersistenceContext EntityManager entityManager; public List<Task> listAll() { return entityManager. createNamedQuery("Task.
You can use arquillian-glassfish-embedded-3.1 (also 3.0), arquillian-jbossas-embedded-6 (and older versions), Tomcat, Weld, or Jetty (see Listing 9). After the configuration of dependencies, you can use Arquillian as the test runner. The unit tests are executed by Arquillian transparently.
EJB Unit Testing with Eclipse and OpenEJB
Article on Testing EJB
Glassfish EJB 3.0 Unit testing
JUnitEE Tutorial
Effective Unit Testing EJB 3.0 with OpenEJB
JUnitEE IBM Tutorial
The next version NetBeans 6.8 includes a nice new feature: it generates Unit-Tests for EJB 3.1 with Embeddable Container code.
@Test
public void testHello() throws Exception {
System.out.println("hello");
HelloService instance = (HelloService)javax.ejb.embeddable.EJBContainer.createEJBContainer().getContext().lookup("java:global/classes/HelloService");
String expResult = "";
String result = instance.hello();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With