Full disclosure: I'm contributor of Arquillian
Arquillian is a component model for integration testing
.
By using the EJBContainer
, you bring the runtime(the container in this case) in your tests
. By bringing the runtime in your tests, you add configuration complexity
to them. Arquillian is built on the opposite philosophy
. Arquillian does the opposite thing, it brings your test to the runtime
and thus it eliminates the testing bandgap
(gap in complexity while moving from unit to integration testing).
You will realize the above mentioned difference in the below examples.
Test an EJB using Arquillian:
@RunWith(Arquillian.class)
public class ArquillianGreeterTest {
@Deployment
public static JavaArchive createTestArchive() {
return ShrinbkWrap.create("greeterTest.jar", JavaArchive.class)
.addClasses(Greeter.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@EJB private Greeter greeter;
@Test
public void testGreeting() {
assertNotNull(greeter);
assertEquals("Welcome to the Arquillian Universe :)", greeter.greet());
}
}
The same example using EJBContainer, would look like:
public class EJBContainerGreeterTest {
private static EJBContainer ejbContainer;
private static Context ctx;
@BeforeClass
public static void setUpClass() throws Exception {
ejbContainer = EJBContainer.createEJBContainer();
ctx = ejbContainer.getContext();
}
@AfterClass
public static void tearDownClass() throws Exception {
if (ejbContainer != null) {
ejbContainer.close();
}
}
@Test
public void testGreeting() {
Greeter greeter = (Greeter)
ctx.lookup("java:global/classes/Greeter");
assertNotNull(greeter);
assertEquals("Welcome to the Arquillian Universe :)", greeter.greet()) ;
}
}
I hope this helps.
EJBContainer
is specific for EJBs. Let's say your application runs on GlassFish, how would you get theEJBContainer
? How would you test things like REST endpoints or JSF controllers? Arquillian is more full spectrum than just testing EJBs. Maybe if you provided more of your use case it would easier to answer. – Cloud