Saturday, December 06, 2008

EJB testing: second thought

I had proposed a way of testing EJBs outside the container. The problem would that is that it wouldn't be normal to test a bean who's life cycle depends heavily on the container outside of it. The solution would be an embedded server, such as emdedded Glassfish

I am not sure it currently has EJB support, I couldn't find information to clear things out, but it's on it's way. Digging a little, I found that they are other EJB embedded containers out there, like OpenEJB(the EJB 3 container for Apache Geronimo and WebSphere Community Edition) or Embedded JBoss. The vision here, a Java EE 6/EJB 3.1 vision, would be to have something like this:


@RunWith(EmbeddableEJB3Runner.class)
public class PlaceBidTest {
@EJB
private PlaceBid placeBid;

@Test
public void testAddBid() {
placeBid.addBid(new Bid("rrahman", 10059, 200.50));
}
}

Now this is beautiful :)