JBoss.orgCommunity Documentation
Arquillian's forte is not only in its ease of use, but also in its flexibility. Good integration testing is not just about testing in any container, but rather testing in the container you are targeting. It's all too easy to kid ourselves by validating components in a specialized testing container, only to realize that the small variations causes the components fail when it comes time to deploy to the application for real. To make tests count, you want to execute them in the real container.
Arquillian supports a variety of target containers out of the box, which will be covered in this chapter. If the container you are using isn't supported, Arquillian makes it very easy to plug in your own implementation.
There are two styles of containers that you can target in Arquillian:
remote — resides in a separate JVM from the test runner; its lifecycle may be managed by Arquillian, or Arquillian may bind to a container that is already started
embedded — resides in the same JVM as the test runner; its lifecycle is likely managed by Arquillian
Containers can be further classified by their capabilities. There are three common catagories:
A fully compliant Java EE application server (e.g., GlassFish, JBoss AS, Embedded GlassFish)
A Servlet container (e.g., Jetty, Tomcat)
A standalone bean container (e.g., Weld SE, Spring)
Arquillian provides SPIs that handle each of the tasks involved in controlling the runtime environment, executing the tests and aggregating the results. So in theory, you can support just about any environment that can be controlled with the set of hooks you are given.
The implementations provided so far are shown in the table below. Also listed is the artifactId of the JAR that provides the implementation. To execute your tests against a container, you must include the artifactId that corresponds to that container on the classpath. Use the following Maven profile definition as a template to add support for a container to your Maven build, replacing %artifactId% with the artifactId from the table. You then activate the profile when executing the tests just as you did in the Chapter 3, Getting started chapter.
<profile>
<id>%artifactId%</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>%artifactId%</artifactId>
<version>${arquillian.version}</version>
</dependency>
</dependencies>
</profile>
Table 4.1. Target containers supported by Arquillian
Container name | Container type | Spec compliance | artifactId |
---|---|---|---|
JBoss AS 5.1 | remote | Java EE 5 | arquillian-jbossas-remote-51 |
JBoss AS 6.0 M2 | remote | Java EE 6 | arquillian-jbossas-remote-60 |
Embedded GlassFish V3 | embedded | Java EE 6 | arquillian-glassfish-embedded-30 |
Weld SE | embedded | CDI | arquillian-weld-embedded |
Apache OpenEJB | embedded | EJB 3.0 | arquillian-openejb |
Support for other containers is planned, including GlassFish V3(remote), Tomcat and Jetty. We don't have plans to provide implementations for Spring or Guice at this time, but we welcome a contribution from the community, because it's certainly possible.