Language: Java
Testing/Integration
Arquillian was created to overcome limitations of traditional unit testing frameworks for enterprise applications. It provides a way to deploy your code in a container, run tests against it, and verify real-world interactions, making integration testing easier, repeatable, and closer to production scenarios.
Arquillian is a powerful testing platform for Java that simplifies integration and functional testing of Java EE and Jakarta EE applications. It allows developers to execute tests inside real runtime containers rather than mocks, ensuring realistic behavior and deployment conditions.
Add dependencies in pom.xml:
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.7.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-embedded</artifactId>
<version>3.0.0.Final</version>
<scope>test</scope>
</dependency>Add dependencies in build.gradle:
testImplementation 'org.jboss.arquillian.junit:arquillian-junit-container:1.7.0.Final'
testImplementation 'org.jboss.arquillian.container:arquillian-weld-embedded:3.0.0.Final'Arquillian allows developers to write tests that run inside real or embedded containers. It manages the deployment lifecycle, container startup, and test execution, and integrates with popular testing frameworks like JUnit and TestNG.
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class MyServiceTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(MyService.class)
.addAsManifestResource("beans.xml");
}
@Test
public void testServiceMethod() {
MyService service = new MyService();
assertEquals("Hello", service.sayHello());
}
}Defines a deployment package using ShrinkWrap and runs a simple test in the Arquillian-managed container.
import javax.inject.Inject;
@Inject
MyService service;
@Test
public void testInjectedService() {
assertEquals("Hello", service.sayHello());
}Demonstrates dependency injection in tests to access container-managed beans.
// In arquillian.xml, configure container:
// <container qualifier="wildfly" default="true">
// <configuration>
// <property name="managementAddress">localhost</property>
// <property name="managementPort">9990</property>
// </configuration>
// </container>Arquillian supports multiple containers such as WildFly, GlassFish, and TomEE, configured via arquillian.xml.
@RunWith(Arquillian.class)
public class MyTestNGTest extends AbstractTestNGSpringContextTests {
// TestNG methods with @Test annotations
}Arquillian can also integrate with TestNG instead of JUnit.
Use ShrinkWrap to define minimal deployment packages containing only required classes and resources.
Leverage embedded containers for fast, repeatable tests during development.
Use Arquillian Drone or Selenium integration for functional web testing.
Separate unit tests and integration tests clearly to maintain test speed.
Configure container-specific settings in arquillian.xml to match production environments.