testing the enterprise layers, with arquillian
DESCRIPTION
Arquillian is an innovative and highly extensible testing platform for the JVM that enables developers to easily create automated integration, functional and acceptance tests for Java middleware, from Java EE and beyond. For years we’ve been exploring how to layer and separate our code to test in isolation on the unit level. We’ve kept integration and functional testing as a big ball of mud; jumping straight from unit to full system testing. But can we apply some of the same lessons learned from unit to integration testing? Speaker Bio: Arquillian project lead, Aslak Knutsen, is a Senior Software Engineer at Red Hat where he is working on projects such as Arquillian and ShrinkWrap, one of the founders of the JBoss Testing initiative and a speaker at major industry conferences including JavaOne, Devoxx, Jazoon, JFokus, Geecon, JUDCon and JBoss World.TRANSCRIPT
Greetings,Earthlings!
1Tests should beportable to any supported container
2Tests should beexecutable from both IDE and build tool
3The platform shouldextend/integrate existing test
frameworks
The basics
Arquillian Coreso you can rule the code, not the bugs!
Testingplatform
Middleware for your tests
Modular, Extensible, Flexible
Test ExtensionSPI for test runners
Test RunnersJUnit · TestNG · Spock · JBehave · Cucumber · Thucydides
ContainerExtensionSPI for runtime providers
ContainerAdapters
WildFly · JBoss EAP · GlassFish · TomEE · Jetty · Tomcat ·WebSphere · WebLogic · Spring · Weld · OSGi · Android · iOS
Container TestExtension
Binds the two ⇒ In container testing
The basic Test Class
public class MyTestClass {
private MyBean bean = new MyBeanStub();
@Test public void shouldBeAbleTo() { Assert.assertNotNull(bean); }}
@RunWith(Arquillian.class)public class MyTestClass {
@Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class) .addXYZ(...); }
@Inject private MyBean bean;
@Test public void shouldBeAbleTo() { Assert.assertNotNull(bean); }}
Demo
How does this all work?
SetupMaven, Gradle, Ant(+Ivy)
<dependencyManagement> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>1.1.5.Final</version> <scope>import</scope> <type>pom</type> </dependency></dependencyManagement>
<dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <scope>test</scope></dependency>
@RunWith(Arquillian.class)public class MyTestClass {
@Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(WebArchive.class) .addXYZ(...); }
@Inject private MyBean bean;
@Test public void shouldBeAbleTo() { Assert.assertNotNull(bean); }}
<profile> <id>arq-jbossas-remote-7</id> <dependencies> <dependency> <groupId>org.jboss.as</groupId> <artifactId>jboss-as-arquillian-container-remote</artifactId> <version>${version.jbossas}</version> </dependency> </dependencies></profile>
ShrinkWrapDeployment + Resolver + Descriptors
ShrinkWrap.create(JavaArchive.class) .addClasses(x) .addPackages(x.z)
ShrinkWrap.create(WebArchive.class) .addAsLibraries(x) .addAsWebInfResource(x) .setWebXML(z)
ShrinkWrap.create(EnterpriseArchive.class) .addAsModules(war, jar) .setApplicationXML(x)
Maven.resolver() .loadPomFromFile("pom.xml") .resolve("x:v", "x:y:1.0") .withTransitivity() .asFile();
Descriptors.create(WebAppDescriptor.class) .metadataComplete(true) .version("2.5") .createServlet() .servletName(EchoServlet.class.getSimpleName()) .servletClass(EchoServlet.class.getName()).up() .createServletMapping() .servletName(EchoServlet.class.getSimpleName()) .urlPattern(EchoServlet.URL_PATTERN).up() .exportAsString()
Run modes