Professional Documents
Culture Documents
ARQUILLIAN
Container Services
POJO Model
JNDI EJB2.x
Seam
CDI Weld
Arquillian
Real EE Testing
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 see the results of the test? How does test isolation work?
Test
classpath-hell
Can
Challenges
Challenges to testing in container
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
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?
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
18
Case Study
19
Arquillian Runner
@RunWith(Arquillian.class)
JUnit
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
Arquillian injects the bean into the test class instance, before running any tests.
24
Write
No record-replay-verify model Assert as you typically do Use real objects in your assertions
25
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
28
29
30
31
32
33
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 ?