The simplest “micro” deployment (ArqTip #2)

read the asciidoc based version of this post here.

The second Arquillian tip is the simplest “micro” deployment. Its a Arquillian deployment that uses the hole project as deployment with no need for adding individual classes, packages or libraries:



Since ShrinkWrap 3 it is now possible to generate a deployment with everything on classpath using shringwrap api:

    public static Archive<?> createDeployment() {
        WebArchive war = (WebArchive) EmbeddedMaven.forProject(new File("pom.xml"))

        war.addAsResource("persistence.xml", "META-INF/persistence.xml");//replace with test persistence
        return war;


public class SimplestDeployment {

    public static Archive&lt;?&gt; createDeployment() {
        WebArchive war = ShrinkWrap.create(ZipImporter.class, "cdi-crud.war").
                importFrom(new File("target/cdi-crud.war")).as(WebArchive.class);
        war.addAsResource("persistence.xml", "META-INF/persistence.xml");//replace with test persistence
        return war;

    CarService carService;

    public void shouldCountCars() {
        assertEquals(carService.crud().count(), 4);

This basically uses a previously builded project as deployment and just replaces its persistence.xml to use a test database.

Compare it with a traditional deployment here.

Of course that this simplicity comes with a price:

1 – Its not a true micro deployment because it uses the hole application. If your application is big the deployment can take considerable time(seconds);

2 – You need to build the application before running the test. Here you lose a big advantage of Arquillian which is to not build the application if a test (even functional tests) has failed.

To overcome problem #2 you can execute the tests in surefire integration-tests phase:



There is an issue from 2012 in Arquillian issue tracker which address this feature of a “simplest deployment”  using a single annotation , see the issue here:

Source code of this post can be found here:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s