Extreme Java When vanilla Java is not enough


Unit Testing EJBs 3.1 with Glassfish Embedded

Pretty simple, indeed. You need the "glassfish-embedded-all-3.0-b74b.jar", and use the new EJBContainer like this:

MyBean ejb = (MyBean) EJBContainer
assertEquals(3, ejb.add(1, 2));

And remember that you can use a deployment descriptor on your test classpath to customize both transaction and datasource for your unit testing.

If you are using maven, use this dependency instead of javaee-api:


If you put "javaee-api" as "provided" and GF as "test", you will receive nasty "Abscent Code" errors.