testing the enterprise layers, with arquillian

37
Greetings, Earthlings!

Upload: virtual-jboss-user-group

Post on 22-Jun-2015

344 views

Category:

Software


0 download

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

Page 1: Testing the Enterprise layers, with Arquillian

Greetings,Earthlings!

Page 2: Testing the Enterprise layers, with Arquillian

1Tests should beportable to any supported container

Page 3: Testing the Enterprise layers, with Arquillian

2Tests should beexecutable from both IDE and build tool

Page 4: Testing the Enterprise layers, with Arquillian

3The platform shouldextend/integrate existing test

frameworks

Page 5: Testing the Enterprise layers, with Arquillian

The basics

Page 6: Testing the Enterprise layers, with Arquillian

Arquillian Coreso you can rule the code, not the bugs!

Page 7: Testing the Enterprise layers, with Arquillian

Testingplatform

Middleware for your tests

Page 8: Testing the Enterprise layers, with Arquillian

Modular, Extensible, Flexible

Page 9: Testing the Enterprise layers, with Arquillian

Test ExtensionSPI for test runners

Page 10: Testing the Enterprise layers, with Arquillian

Test RunnersJUnit · TestNG · Spock · JBehave · Cucumber · Thucydides

Page 11: Testing the Enterprise layers, with Arquillian

ContainerExtensionSPI for runtime providers

Page 12: Testing the Enterprise layers, with Arquillian

ContainerAdapters

WildFly · JBoss EAP · GlassFish · TomEE · Jetty · Tomcat ·WebSphere · WebLogic · Spring · Weld · OSGi · Android · iOS

Page 13: Testing the Enterprise layers, with Arquillian

Container TestExtension

Binds the two ⇒ In container testing

Page 14: Testing the Enterprise layers, with Arquillian

The basic Test Class

Page 15: Testing the Enterprise layers, with Arquillian

public class MyTestClass {

private MyBean bean = new MyBeanStub();

@Test public void shouldBeAbleTo() { Assert.assertNotNull(bean); }}

Page 16: Testing the Enterprise layers, with Arquillian

@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); }}

Page 17: Testing the Enterprise layers, with Arquillian

Demo

Page 18: Testing the Enterprise layers, with Arquillian

How does this all work?

Page 19: Testing the Enterprise layers, with Arquillian

SetupMaven, Gradle, Ant(+Ivy)

Page 20: Testing the Enterprise layers, with Arquillian

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

Page 21: Testing the Enterprise layers, with Arquillian

@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); }}

Page 22: Testing the Enterprise layers, with Arquillian
Page 23: Testing the Enterprise layers, with Arquillian

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

Page 24: Testing the Enterprise layers, with Arquillian
Page 25: Testing the Enterprise layers, with Arquillian
Page 26: Testing the Enterprise layers, with Arquillian

ShrinkWrapDeployment + Resolver + Descriptors

Page 27: Testing the Enterprise layers, with Arquillian

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)

Page 28: Testing the Enterprise layers, with Arquillian

Maven.resolver() .loadPomFromFile("pom.xml") .resolve("x:v", "x:y:1.0") .withTransitivity() .asFile();

Page 29: Testing the Enterprise layers, with Arquillian

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()

Page 30: Testing the Enterprise layers, with Arquillian
Page 31: Testing the Enterprise layers, with Arquillian
Page 32: Testing the Enterprise layers, with Arquillian
Page 33: Testing the Enterprise layers, with Arquillian
Page 34: Testing the Enterprise layers, with Arquillian

Run modes

Page 35: Testing the Enterprise layers, with Arquillian
Page 36: Testing the Enterprise layers, with Arquillian
Page 37: Testing the Enterprise layers, with Arquillian