testingmodulestructurecontainersjboss-arquillian

how to use arquillian for integration tests having multi maven modules


I have multiple maven modules: DBLayer (Contains all entities),UserManagement (User management services), WebApp

For setting up the testing i need to understand how to structure everything.

I want to test each module in an embedded container. As you all know, in each module I have my test folder where I put my test classes. Do I have to put the ShrinkWrap setup in each module test class (code that prepares embedded container for testing), or is that only needed in the webapp?

I also have the arquillian dependencies in each module pom file. Is there a better way to add these dependencies?

Thank you in advance.


Solution

  • I want to test each module in an embedded container (...)

    If you are considering an embedded container, please take a look at this answer. Dan Allen explains it in details in his short article The Danger of Embedded Containers. Please take a look at it.

    It looks to me that you are using Maven, then the following answer you may find useful in terms of separating integration tests from unit tests. To be short: stick to the Maven naming conventions (just name your integration tests with *IT suffix, e.g. MyClassIT.java) and let maven-failsafe-plugin do its job.


    Do I have to put the ShrinkWrap setup in each module test class (code that prepares embedded container for testing), or is that only needed in the webapp?

    Unfortunately yes. That is because you may want to prepare a different deployment for each test class. But drawbacks are clear:

    1. Usually repeated deployment's setup.
    2. Slowed down execution of tests (there is a new deploy operation for every test case)

    Fortunately, there is Arquillian Suite Extension that lets you achive that. The Extension will force all classes in a TestSuite to run from the same DeploymentScenario. But as far as I know, it is more complex topic than it would appear on the surface - just keep in mind that this extension (although extremely useful) may not work with some other arquillian extensions.


    I also have the arquillian dependencies in each module pom file. Is there a better way to add these dependencies?

    Your intuition is correct:) Yes, there are better ways. Personally I would recommend keep dependency to the arquillian only in a parent pom.xml file, then all sub-modules would inherit this dependency.

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.1.5.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
    

    Generally, be sure to read Getting started with Arquillian Guide.