HTMLUnit is great to test web applications but sadly it doesn’t support recent js libraries (AngularJs/JQuery to not say their names).
PhantomJs is a great alternative but sometimes setup can be boring or too complicated for what you need.
HTMLUnit is great to test web applications but sadly it doesn’t support recent js libraries (AngularJs/JQuery to not say their names).
PhantomJs is a great alternative but sometimes setup can be boring or too complicated for what you need.
OpenEJB/TomEE ApplicationComposer design is to describe a test application with an in memory model close to the xml EE one (Beans for beans.xml, EjbJar for ejb-jar.xml…).
But when it comes to CDI and since it was mainly designed for small apps it is hard to say “I have a CDI dependency/library”.
The more obvious use case is DeltaSpike!
To make it easier we added @Jars recently.
If you read this post you surely know some “common” ways to test EE applications with JUnit using a runner. It often looks like:
@RunWith(CdiTestRunner.class) public class MyEETestWithDeltaSpike { @Inject private ACdiBean bean; @Test public void theTest() { // do test } }
or
@RunWith(EJBContainerRunner.class) public class MyEETestWithOneOpenEJB { @Inject private ACdiBean bean; @Test public void theTest() { // do test } }
These tests have something in common: they use the classpath to deploy and don’t need something else (compared to Arquillian or ApplicationComposer).
That’s great but you bind your test lifecycle to the specific runner. It means you can’t compose runners and you can’t do anything before the container bootstrap like starting a FTP server with rule-them-all or just using JUnit Theories or Parameterized runners.
To test a EE application you have several solutions. One of them is to use EJBContainer.
EJBContainer container = EJBContainer.createEJBContainer(properties); // do test container.close();
These steps are often in a test lifecycle (@BeforeClass/@AfterClass for JUnit for instance).
With OpenEJB you also have:
container.getContext().bind("inject", this);
This allows you to get injections (@Inject, @Resource, @PersistenceContext…) in the test class.
That’s nice but you can make it easier!
Testing your application in your build is mandatory today. Not doing it simply means you don’t know what you’ll provide. That’s why libraries like arquillian are born. However openejb always thought of it and the goal of this post is to share different ways to test an application with OpenEJB and TomEE.