You are on page 1of 39

INTEGRATION TEST WITH

REAL EE TESTING WITH ARQUILLIAN


Presented by Wael ANIBA - UP JEE @ESPRIT - 2013/2014 - wael.aniba@esprit.tn

ARQUILLIAN

Java EE Development Evolution

Container Services

POJO Model

Dependency Framework Ease of Ease of Injection Integration Development Testing

JNDI EJB2.x

Struts Spring Hibernate

EJB3 JPA JSF

Seam

CDI Weld

Arquillian

Real EE Testing

Shift Focus to Testing in EE


Lots

of developers abandoned EE in search of greener testing pastures. Testing has not been the focus for most of the platforms history. Container-based components cry out for ease of testability! Ride the wave encourage support and adoption

Real EE Testing
What does real mean?

Unit testing using doubles, Fakes, Stubs or Mocks can only get us so far when working with container managed resources. We need to test components, not just the classes. Put the tests in the container managing container within the test. rather than

Get the interactions correct between container and its managed resources.

How to do it?
Rolling Your Own
How

do I get unit test class into the container?


Remote

deployment (using hook into server) Bootstrap container inside test


How

do I see the results of the test? How does test isolation work?
Test

classpath-hell

Can

I call it from IDE and get results?

Challenges
Challenges to testing in container

High barrier to entry

Substantial code, configuration and infrastructure

Most dont run from IDE - wheres the feedback? Most arent reusable tied to one projects build Often slow (think mvn package) Cant interact with containers from test (all black-box testing)
6

Arquillian

The Arquillian invasion takes up the challenge

Arquillian Features

JUnit

or TestNG compatible Abstracts out server lifecycle and deployment Injects container managed resources into test Zero reliance on build run straight from IDE Two container modes remote/embedded Pass-by-reference between test and server Extensible SPI to plug any container in Single test executed against all containers

Arquillian Architecture

Case Study

WHY ARQUILLIAN?

How does this solve our problems?

10

Case Study

11

Case Study

12

Case Study

13

Case Study

Implementations matter
Testing with real Objects

14

Case Study

15

Case Study

16

Case Study

17

Case Study

Bringing the code as close as possible to production

Arquilliant enters the scene

18

Case Study

19

Arquillian Runner

@RunWith(Arquillian.class)
JUnit

>= 4.8.1 TestNG > 5.12.1

20

ShrinkWrap
@Deployment
Assemble

test archives with ShrinkWrap Bundles the: Class/component to test Supporting classes Configuration and resource files Dependent libraries

21

ShrinkWrap
// #1 // #2 // #3

// #4

1. Annotate the method with @Deployment 2. Create a new JavaArchive. This will eventually create a JAR. 3. Add our Class-Under-Test to the archive. 4. Add an empty file named beans.xml to enable CDI. 22

Test enrichment

Arquillian

can enrich test class instances with dependencies. Supports: @EJB @Inject @Resource @PersistenceContext @PersistenceUnit @ArquillianResource Etc
23

Revisiting dependency injection

Arquillian injects the bean into the test class instance, before running any tests.

24

Writing your tests

Write

assertions as you normally would

No record-replay-verify model Assert as you typically do Use real objects in your assertions

25

Running your tests

Run

the tests from your IDE or from your CI server, just like you would run unit tests Run as JUnit test - Alt+Shift+X, T Run as Maven goal - Alt+Shift+X, M

26

Lets recap
// Use the Arquillian test runner.
// A SessionBEan Bean, managed by the container, injected by Arquillian.

// Assemble a microdeployment.

// Test like you normally do. No mocks. Just the real thing.

27

Under the hood

WHAT DID YOU JUST SEE?

The stuff that Arquillian does under the hood

28

Under the hood


Maven Profile

29

Under the hood

30

Under the hood

31

Under the hood

32

Under the hood

33

Under the hood

34

Arquillian Extensions

Drone: testing web-based user interface Graphene: extensions for Selenium Persistence: help writing tests where persistence layer is involved. Performance: checking that the performs within a specific range Seam 2: testing applications created with Seam 2 framework JBehave: BDD/TDD&ATDD with Arquillian Etc

35

Arquillian .org

36

References

docs.jboss.org Reference Guide arquillian.org Chris Wash - CapTech Ventures Alexis HASSLER softShake - 2nd edition - Genve Vineet Reynolds - Testing with real objects

37

QUESTIONS ?

REAL EE TESTING WITH ARQUILLIAN


Presented by Wael ANIBA - UP JEE @ESPRIT - 2013/2014 - wael.aniba@esprit.tn

You might also like