37
Greetings, Earthlings!

Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak Knutsen

Embed Size (px)

Citation preview

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