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 ShrinkWrap 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;

EDIT: The option useMaven3Version(“3.3.9”) will download (and cache) the maven distribution from apache file servers. If you are behind a proxy you may have problems, in this case you can change the download URL with useDistribution:

   WebArchive war = (WebArchive) EmbeddedMaven.forProject(new File("pom.xml"))
      .useDistribution(new URL("https://internal/artifactory/ext-release-local/apache-maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.tar.gz"),

In the example above EmbededMaven will download maven distribution from the URL you pass in distribution param.

Source code of this post can be found here.



Test your REST endpoints inside the container (ArqTip #1)


read the asciidoc based version of this post here.


Since Arquillian 1.1.9.Final it is possible to get deployment URL even in in-container tests. This enables REST endpoints testing inside the container.

The main advantage of running this kind of test inside the container (same JVM) is that you can call any service/method of your application before making the (test)rest call.

Even better, you can prepare your database or whatever configuration you need before running the test. Here is an example using arquillian persistence (which doesn’t work outside the container – see Arq1077):



public class CrudRestIt {

    @Deployment(name = "cdi-rest.war")
    public static Archive<?> createDeployment() {
        WebArchive war = Deployments.getBaseDeployment();
        MavenResolverSystem resolver = Maven.resolver();
        return war;

    URL basePath;

    public void shouldListCars() {
                queryParam("start", 0).queryParam("max", 10).
                get(basePath + "rest/cars").
                body("", hasSize(4)).//dataset has 4 cars
                body("model", hasItem("Ferrari")).
                body("price", hasItem(2450.8f)).


Note that I have included two libs into the deployment, RestAssured and Gson because both are used inside the test.

As a bonus you can get code coverage of your REST endpoints, something you don’t have when running as client (testable=false a.k.a blackbox):





Test source code can be found here: