简体   繁体   中英

Integration test of local EJB on Glassfish

I am a little confused about integration testing of a simple EJB. If I want to test the EJB's local interface/no-interface do I need to use Arquillian? I stumbled upon Arquillian but I have never used it. I have a Maven directory structure/Glassfish and Eclipse Indigo

If I want to test the EJB's local interface/no-interface do I need to use Arquillian?

It is not necessary to use Arquillian, but there are certain things made easier when you do so.

Ordinarily, you would merely use the EJBContainer API available in EJB 3.1 for testing of EJBs in an embedded container (that runs in the same JVM as the tests). In the case of embedded Glassfish, this typically results in deployment of EJBs that are found in the classpath of the application.

Arquillian allows you to do a lot more than execute tests in a container. It manages the lifecycle of the container, thus not requiring any writing of code beyond setting the properties in the arquillian.xml file. It allows you to manage deployments to a container in a far more easier manner; using the ShrinkWrap API, one can programmatically perform different context-sensitive deployments to a container. Furthermore, injection of dependencies (test enrichment) can also be performed, so long as they're supported by Arquillian.

It would suffice to know that the embedded Glassfish container support for Arquillian, uses the same APIs that are exposed by the embedded Glassfish API; usually you might end up duplicating the work of Arquillian, except in certain unique scenarios.

If you're interested in taking a look at examples using Arquillian, this GitHub project would help.

When you are not a fan of mocking (just like me), then you could either have a look at ejb3unit (http://ejb3unit.sourceforge.net/), or try Arquillian.

I must say I had very good experiences with "ejb3unit".

But it seems that "EJB3unit" peoject was not maintenance since 2-3 years. But supprisingly, weeks ago, there are again some activities on the ejb3unit site.

Arquillian is not so easy start with. I would say this mainly lies in the documentation, missing running examples, and good turorials.

But so long as you have made your firt Arquillian test run, Arquillian begins to shine!

Under the following link, you could find a tutorial serial on step by step setting up Arquillian:

http://milestonenext.blogspot.de/2012/12/ejb3-integration-test-with-arquillian.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM