I'm doing my first Java EE project and I want to preform a test. I searched and found that since EJB 3.1, there's the possibility of using an embedded EJB container to test the business layer. I'm using WildFly but I haven't found how to configure the embedded container.
So, how to configure the embedded container properly and test EJBs 3.1+ with WildFly?
I appreciate any help!
You must use framework arquillian from jboss itself http://www.mastertheboss.com/jboss-frameworks/arquillian/arquillian-tutorial.
What this framework does is this: in the background the instance of jboss is created. Everything is deployed there so you can then run your ejb's or servlets on that "background" container.
It is not easy to configure it, so I would recommend you to start with Jboss Tools for eclipse. Code looks then like this:
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test-demo.war")
.addAsResource("META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
I do not favor this approach, it's really a separate deployment, you need to understand fully the structure of WAR and EJB packages and all other details.
It's really better, that you your EJB's , JPAs and Servlet beans are just light wrappers around normal java classes (POJO's), where the real logic resides. Then you can use plain unit tests to test those.
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