How to use arquillian for integration tests with multiple maven modules
I have several maven modules: DBLayer (contains all entities), UserManagement (user management services), WebApp
To set up testing, I need to understand how to structure everything.
I want to test every module in an embedded container. As you all know, in each module I have a test folder where I put my test classes. Do I have to install ShrinkWrap on every test class of the unit (the code that prepares the inline container for testing), or is it only necessary in the webapp?
I also have arkil dependencies in each module of the pom file. Is there a better way to add these dependencies?
Thanks in advance.
source to share
I want to test each module in an inline container (...)
If you are considering an inline container, please see this answer .
Dan Allen explains this in detail in his short article The Dangers of Embedded Containers . Please take a look at this.
It looks to me like you are using maven, followed by the following answer , which might be helpful in terms of separating integration tests from unit tests.
In short: stick with maven conventions (just list your integration tests with a suffix *IT
for example MyClassIT.java
) and let it maven-failsafe-plugin
do its job.
Do I have to install ShrinkWrap on each test class of the unit (the code that prepares the built-in container for testing), or is it only necessary in the webapp?
Unfortunately yes. This is because you can prepare a different deployment for each test class. But the disadvantages are obvious:
- Typically a repetitive deployment setup.
- Slower test execution (there is a new deployment operation for each test case)
Fortunately , there is an Arquillian Suite Extension that allows you to achieve this. The extension makes all classes in TestSuite run from the same DeploymentScenario
.
But as far as I know, this is a more complex topic than meets the eye - just keep in mind that this extension (albeit extremely useful) may not work with some other Arcillian extensions.
I also have arkil dependencies in each module of the pom file. Is there a better way to add these dependencies?
Your intuition is correct :) Yes, there are better ways.
Personally, I would recommend keeping the arquillian dependency only in the parent pom.xml
file, then all submodules 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>
All in all, be sure to read Getting Started with the Arquillian guide .
Good luck.
source to share