SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Real Java EE Testing
  with Arquillian and ShrinkWrap




         Don't mock me.




Aslak Knutsen
Senior Software Engineer
JBoss, by Red Hat
Agenda                                                                         #arquillian

    ●   Barriers to testing
    ●   Rethinking integration testing
    ●   ShrinkWrap
    ●   Arquillian
    ●   Demo, demo, demo
    ●   Future
    ●   Q&A




2                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Unit tests vs integration tests

    Unit                                             Integration
    ●   Fine-grained                                   ●   Coarse-grained
    ●   Simple                                         ●   Complex
    ●   Single API call                                ●   Component interactions
    ●   Fast, fast, fast                               ●   Sloooooooow
    ●   Easily run in an IDE                           ●   Run in an IDE? How?




3                   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Common integration testing challenges

    ●   Start a container environment
    ●   Run a build to create/deploy application archive
    ●   Mock dependent components
    ●   Configure application to use test data source(s)
    ●   Deal with (lack of) classpath isolation




4                  Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
The “testing bandgap” and compounding effort
Thought and Effort




                                                                                                     Functional complexity

                                                                                                     Configuration complexity




                     Unit Tests                    Integration Tests                          Functional Tests


5                                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
What if integration testing could be...

    ●   as easy as writing a unit test
    ●   run in the IDE, leveraging incremental builds
    ●   limited to select components running in isolation
         ●   ...avoiding the “big bang” integration roadblock




6                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Skip the Build!
                                                        Test in-container!




7   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
An in-container approach to integration testing

    1. Start or connect to a container
    2. Package and deploy test case* as archive
    3. Run test in-container
    4. Collect results
    5. Undeploy test archive




8                Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
container

    n. a process that manages a runtime environment and provides
    resources, a component model and a set of services




9          Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Containers and components

     ●   Component
          ●   Follows standard programming model
          ●   Encapsulates business logic
          ●   Packaged in deployable archive



     ●   Container
          ●   Loads and executes components
          ●   Provides services and resources


10                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
s ing
                                  mis
     What's been from Java EE?
                ^




11   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
A component model
                                                         for your tests




12   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Arquillian's testing continuum
              Reducing enterprise testing to child's play
Thought and Effort




                                                                                                     Functional complexity

                                                                                                     Configuration complexity




                     Unit Tests                    Integration Tests                          Functional Tests


13                                Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
How do we get there?




14   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Step 1: Liberate tests from the build!

     ●   Adds overhead to development cycle
     ●   Slows down test execution
     ●   Uses coarse-grained classpath/package



     ●   Keep it manageable!
          ●   Well-defined “unit”
          ●   Classpath control



15                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Project lead: Andrew Lee Rubinger



     n. a fluent Java API for programmatic creation of archives like
     JARs, WARs and EARs; developed by the JBoss Community




16           Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Benefits of ShrinkWrap

     ●   Incremental IDE compilation
          ●   Save and re-run
          ●   Skip the build!
     ●   Simple, fluent API
     ●   Micro deployments
     ●   Export and debugging
     ●   Tooling views (future)




17                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Fluent archive creation
     final JavaArchive archive =
     ShrinkWrap.create(JavaArchive.class, "slsb.jar")
         .addClasses(Greeter.class, GreeterBean.class);
     System.out.println(archive.toString(true));

 Yields output:

     slsb.jar:
     /com/
     /com/acme/
     /com/acme/app/
     /com/acme/app/ejb3/
     /com/acme/app/ejb3/Greeter.class
     /com/acme/app/ejb3/GreeterBean.class




18                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Build, what build?
     @Deployment
     public static Archive<?> createDeployment() {
       return ShrinkWrap.create(JavaArchive.class)
         .addClasses(Greeter.class, GreeterBean.class);
     }




19                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Skip the build!
     @Deployment
     public static Archive<?> createDeployment() {
       return ShrinkWrap.create(JavaArchive.class)
         .addPackage(TemperatureConverter.class.getPackage())
         .addManifestResource(EmptyAsset.INSTANCE,
     "beans.xml");
     }




20                Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Step 2: Gut the plumbing!

     ●   Manage lifecycle of container
     ●   Enrich test class
     ●   Package test archive
     ●   Deploy test archive
     ●   Invoke tests
     ●   Capture test results


     ●   What's left?
          ●   Pure test logic

21                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Project lead: Aslak Knutsen



     n. a container-oriented testing framework that abstracts away
     container lifecycle and deployment from test logic so developers
     can easily develop a broad range of integration tests for their
     enterprise Java applications; developed by the JBoss Community




22           Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Arquillian project mission




         Make integration testing a breeze!




23         Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Prove it.
     @RunWith(Arquillian.class)
     public class GreeterTestCase {

      @Deployment
      public static Archive<?> createDeployment() {
        return ShrinkWrap.create(JavaArchive.class)
          .addClasses(Greeter.class, GreeterBean.class);
      }

      @EJB private Greeter greeter;

       @Test
       public void shouldBeAbleToInvokeEJB() throws Exception {
         assertEquals("Hello, Earthlings",
     greeter.greet("Earthlings"));
       }
     }
24                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Benefits of Arquillian

     ●   Write less (test) code
     ●   As much or as little “integration” as you need
     ●   Looks like a unit test, but you're in a real environment!
          ●   Easily lookup component to test
          ●   No hesitation when you need a resource
     ●   Run same test in multiple containers
     ●   It's a learning environment




25                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
How is a container selected?

     ●   Explain...




26                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Arquillian tactical unit

     ●   Unit testing framework runner
     ●   Deployable test archive
     ●   Test enrichers
     ●   Test run mode
     ●   Target container
     ●   Test framework integrations




27                  Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Supported unit testing frameworks




           JUnit                                    TestNG
                >= 4.8.1                                      >= 5.12.1




28         Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Test archive

     ●   Assembled using ShrinkWrap API
     ●   Declared with static @Deployment method
     ●   Bundles:
          ●   Class/component to test
          ●   Supporting classes
          ●   Configuration and resource files
          ●   Dependent libraries




29                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Micro deployments

     ●   Deploy components in isolation
     ●   Test one functional unit at a time
     ●   Don't need to wait for full application build/startup
     ●   Incremental integration
          ●   Hand pick components & resources
          ●   No “big bang” integration




30                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Test enrichment

     ●   Injection
          ●   Fields & method arguments
          ●   @Inject, @Resource, @EJB, @PersistenceContext, ...
          ●   CDI producer methods in test class
     ●   Context management
          ●   Request & Conversation  Test method
          ●   Session  Test class
          ●   Application  Test class
     ●   More to come...


31                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Test run modes

     ●   In-container
          ●   Test bundled with @Deployment archive
          ●   Archive deployed to container
          ●   Test runs inside container alongside application code
          ●   Test invokes application code directly (same JVM)
     ●   As client
          ●   @Deployment archive is test archive (unmodified)
          ●   Archive deployed to the container
          ●   Test runs in original test runner
          ●   Test interacts as a remote client (e.g., HTTP client)

32                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Classifying the containers

     ●   By mode
     ●   By compliance




33                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Container modes

     ●   Embedded
         ●   Same JVM as test runner
         ●   Test protocol either local or remote
         ●   Lifecycle controlled by Arquillian
     ●   Remote
         ●   Separate JVM from test runner
         ●   Arquillian connects to running container
         ●   Tests executed over remote protocol
     ●   Managed
         ●   Remote with lifecycle management

34                    Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Container compliance

     ●   Java EE application server (JBoss AS, GlassFish, etc)
     ●   Servlet container (Tomcat, Jetty)
     ●   Managed bean container (Weld SE, Spring)
     ●   OSGi
     ●   Whatever else comes along...




35                  Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Supported containers

     ●   JBoss AS 5.0 & 5.1 – Managed and remote
     ●   JBoss AS 6 – Managed, remote and embedded
     ●   JBoss JCA – Embedded
     ●   GlassFish 3 – Remote and embedded
     ●   Weld – SE embedded and EE mock embedded
     ●   OpenWebBeans – embedded
     ●   OpenEJB 3.1 – embedded
     ●   OSGi – embedded
     ●   Tomcat 6, Jetty 6.1 and Jetty 7 – embedded
     ●   More on the way...
36                 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Container SPI, not just for Java EE
     public interface DeployableContainer {

         void setup(Context context, Configuration configuration);

         void start(Context context) throws LifecycleException;

       ContainerMethodExecutor deploy(Context context,
     Archive<?> archive)
           throws DeploymentException;

         void undeploy(Context context, Archive<?> archive)
             throws DeploymentException;

         void stop(Context context) throws LifecycleException;

     }

37                   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Power tools: test framework integration

     ●   Test frameworks are services too
     ●   Extend component model for tests
     ●   Examples:
          ●   JSFUnit*
          ●   Cobertura
          ●   HTTPUnit
          ●   DBUnit
          ●   Selenium


     * available
38                       Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Arquillian...

     ●   is a container-oriented testing framework
     ●   provides a component model for tests
     ●   handles test infrastructure & plumbing
     ●   ships with a set of container implementations
     ●   provides a little bit of magic ;)




39                   Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Arquillian invasion strategy

     ●   1.0.0.Alpha3 out!
     ●   More containers
     ●   More framework integrations
          ●   DBUnit, HTTPUnit, Selenium
     ●   Cloud
     ●   Performance extension
     ●   Component coverage
     ●   Package-time bytecode manipulation
          ●   Exception, callback, assertion injection
     ●   Tooling
40                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
We're in print!
                                         LOOK INSIDE!




            Enterprise JavaBeans 3.1, Sixth Edition
            O’Reilly - Andrew Lee Rubinger, et al

            http://community.jboss.org/groups/oreillyejb6th

41          Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Get involved!

     ●   Participate with us!
          ●   Share ideas on the forums (or IRC)
          ●   Give us feedback on releases – still in alpha!
     ●   Fork us!
          ●   http://github.com/arquillian
     ●   Meet us!
          ●   #jbosstesting channel on irc.freenode.net
     ●   Write for us!
          ●   Share your stories – Blog! Tweet!
          ●   Document how it works
42                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
The JBoss Testing Initiative

     ●   Comprehensive testing tool “stack”
     ●   Establish a testing culture in Java EE
          ●   #jbosstesting channel on irc.freenode.net
     ●   Filling voids
          ●   ShrinkWrap – Programmatic archive creation
          ●   Arquillian – Managed integration testing
          ●   JSFUnit – Gray-box JSF testing
          ●   Placeebo – Mock Java EE API implementations
          ●   Descriptors
          ●   Unit testing framework enhancements?

43                     Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
Q&A




http://jboss.org/arquillian
http://jboss.org/shrinkwrap

Weitere ähnliche Inhalte

Was ist angesagt?

Divide and stress: the journey to component load test
Divide and stress: the journey to component load testDivide and stress: the journey to component load test
Divide and stress: the journey to component load test
Juan Pedro Escalona Rueda
 

Was ist angesagt? (20)

Arquillian: Helping web developers and QA get along
Arquillian: Helping web developers and QA get alongArquillian: Helping web developers and QA get along
Arquillian: Helping web developers and QA get along
 
A Tour of the Modern Java Platform
A Tour of the Modern Java PlatformA Tour of the Modern Java Platform
A Tour of the Modern Java Platform
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 
Spring Framework 3.2 - What's New
Spring Framework 3.2 - What's NewSpring Framework 3.2 - What's New
Spring Framework 3.2 - What's New
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
 
Projects Valhalla, Loom and GraalVM at JUG Mainz
Projects Valhalla, Loom and GraalVM at JUG MainzProjects Valhalla, Loom and GraalVM at JUG Mainz
Projects Valhalla, Loom and GraalVM at JUG Mainz
 
PushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design DocumentPushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design Document
 
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios ExplainedAAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
AAI 2235-OpenJPA and EclipseLink Usage Scenarios Explained
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot Applications
 
Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021
 
Divide and stress: the journey to component load test
Divide and stress: the journey to component load testDivide and stress: the journey to component load test
Divide and stress: the journey to component load test
 
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
 
How can your applications benefit from Java 9?
How can your applications benefit from Java 9?How can your applications benefit from Java 9?
How can your applications benefit from Java 9?
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016
 

Ähnlich wie September 2010 - Arquillian

SCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage EfficiencySCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage Efficiency
NetApp
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
WO Community
 

Ähnlich wie September 2010 - Arquillian (20)

Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
 
Java Course 6: Introduction to Agile
Java Course 6: Introduction to AgileJava Course 6: Introduction to Agile
Java Course 6: Introduction to Agile
 
"Java memory model for practitioners" at JavaLand 2017 by Vadym Kazulkin/Rodi...
"Java memory model for practitioners" at JavaLand 2017 by Vadym Kazulkin/Rodi..."Java memory model for practitioners" at JavaLand 2017 by Vadym Kazulkin/Rodi...
"Java memory model for practitioners" at JavaLand 2017 by Vadym Kazulkin/Rodi...
 
Arquillian 소개
Arquillian 소개Arquillian 소개
Arquillian 소개
 
테스트 어디까지 해봤니? Arquillian을 이용한 Real Object 테스트
테스트 어디까지 해봤니? Arquillian을 이용한 Real Object 테스트테스트 어디까지 해봤니? Arquillian을 이용한 Real Object 테스트
테스트 어디까지 해봤니? Arquillian을 이용한 Real Object 테스트
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
 
Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)
 
Arquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made EasyArquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made Easy
 
Ahieving Performance C#
Ahieving Performance C#Ahieving Performance C#
Ahieving Performance C#
 
The_Little_Jenkinsfile_That_Could
The_Little_Jenkinsfile_That_CouldThe_Little_Jenkinsfile_That_Could
The_Little_Jenkinsfile_That_Could
 
Ensuring OpenStack Version up Compatibility for CloudOpen Japan 2013-05-31
Ensuring OpenStack Version up Compatibility for CloudOpen Japan 2013-05-31Ensuring OpenStack Version up Compatibility for CloudOpen Japan 2013-05-31
Ensuring OpenStack Version up Compatibility for CloudOpen Japan 2013-05-31
 
SCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage EfficiencySCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage Efficiency
 
SCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage EfficiencySCI Lab Test Validation Report: NetApp Storage Efficiency
SCI Lab Test Validation Report: NetApp Storage Efficiency
 
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
 
Ansible, integration testing, and you.
Ansible, integration testing, and you.Ansible, integration testing, and you.
Ansible, integration testing, and you.
 
Unit testing hippo
Unit testing hippoUnit testing hippo
Unit testing hippo
 
A fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with ArquillianA fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with Arquillian
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Level Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersLevel Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With Testcontainers
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 

Mehr von JBug Italy

JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 Overview
JBug Italy
 

Mehr von JBug Italy (20)

JBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testing
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
AS7 and CLI
AS7 and CLIAS7 and CLI
AS7 and CLI
 
Intro jbug milano_26_set2012
Intro jbug milano_26_set2012Intro jbug milano_26_set2012
Intro jbug milano_26_set2012
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
 
Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGM
 
AS7
AS7AS7
AS7
 
JBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logic
 
JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 Overview
 
Intro JBug Milano - January 2012
Intro JBug Milano - January 2012Intro JBug Milano - January 2012
Intro JBug Milano - January 2012
 
JBoss AS7 Webservices
JBoss AS7 WebservicesJBoss AS7 Webservices
JBoss AS7 Webservices
 
JBoss AS7
JBoss AS7JBoss AS7
JBoss AS7
 
Intro JBug Milano - September 2011
Intro JBug Milano - September 2011Intro JBug Milano - September 2011
Intro JBug Milano - September 2011
 
All the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSAll the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMS
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data Grid
 
Drools Introduction
Drools IntroductionDrools Introduction
Drools Introduction
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - Gatein
 
May 2010 - Infinispan
May 2010 - InfinispanMay 2010 - Infinispan
May 2010 - Infinispan
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
May 2010 - Drools flow
May 2010 - Drools flowMay 2010 - Drools flow
May 2010 - Drools flow
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

September 2010 - Arquillian

  • 1. Real Java EE Testing with Arquillian and ShrinkWrap Don't mock me. Aslak Knutsen Senior Software Engineer JBoss, by Red Hat
  • 2. Agenda #arquillian ● Barriers to testing ● Rethinking integration testing ● ShrinkWrap ● Arquillian ● Demo, demo, demo ● Future ● Q&A 2 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 3. Unit tests vs integration tests Unit Integration ● Fine-grained ● Coarse-grained ● Simple ● Complex ● Single API call ● Component interactions ● Fast, fast, fast ● Sloooooooow ● Easily run in an IDE ● Run in an IDE? How? 3 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 4. Common integration testing challenges ● Start a container environment ● Run a build to create/deploy application archive ● Mock dependent components ● Configure application to use test data source(s) ● Deal with (lack of) classpath isolation 4 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 5. The “testing bandgap” and compounding effort Thought and Effort Functional complexity Configuration complexity Unit Tests Integration Tests Functional Tests 5 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 6. What if integration testing could be... ● as easy as writing a unit test ● run in the IDE, leveraging incremental builds ● limited to select components running in isolation ● ...avoiding the “big bang” integration roadblock 6 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 7. Skip the Build! Test in-container! 7 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 8. An in-container approach to integration testing 1. Start or connect to a container 2. Package and deploy test case* as archive 3. Run test in-container 4. Collect results 5. Undeploy test archive 8 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 9. container n. a process that manages a runtime environment and provides resources, a component model and a set of services 9 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 10. Containers and components ● Component ● Follows standard programming model ● Encapsulates business logic ● Packaged in deployable archive ● Container ● Loads and executes components ● Provides services and resources 10 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 11. s ing mis What's been from Java EE? ^ 11 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 12. A component model for your tests 12 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 13. Arquillian's testing continuum Reducing enterprise testing to child's play Thought and Effort Functional complexity Configuration complexity Unit Tests Integration Tests Functional Tests 13 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 14. How do we get there? 14 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 15. Step 1: Liberate tests from the build! ● Adds overhead to development cycle ● Slows down test execution ● Uses coarse-grained classpath/package ● Keep it manageable! ● Well-defined “unit” ● Classpath control 15 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 16. Project lead: Andrew Lee Rubinger n. a fluent Java API for programmatic creation of archives like JARs, WARs and EARs; developed by the JBoss Community 16 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 17. Benefits of ShrinkWrap ● Incremental IDE compilation ● Save and re-run ● Skip the build! ● Simple, fluent API ● Micro deployments ● Export and debugging ● Tooling views (future) 17 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 18. Fluent archive creation final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "slsb.jar") .addClasses(Greeter.class, GreeterBean.class); System.out.println(archive.toString(true)); Yields output: slsb.jar: /com/ /com/acme/ /com/acme/app/ /com/acme/app/ejb3/ /com/acme/app/ejb3/Greeter.class /com/acme/app/ejb3/GreeterBean.class 18 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 19. Build, what build? @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClasses(Greeter.class, GreeterBean.class); } 19 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 20. Skip the build! @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addPackage(TemperatureConverter.class.getPackage()) .addManifestResource(EmptyAsset.INSTANCE, "beans.xml"); } 20 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 21. Step 2: Gut the plumbing! ● Manage lifecycle of container ● Enrich test class ● Package test archive ● Deploy test archive ● Invoke tests ● Capture test results ● What's left? ● Pure test logic 21 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 22. Project lead: Aslak Knutsen n. a container-oriented testing framework that abstracts away container lifecycle and deployment from test logic so developers can easily develop a broad range of integration tests for their enterprise Java applications; developed by the JBoss Community 22 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 23. Arquillian project mission Make integration testing a breeze! 23 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 24. Prove it. @RunWith(Arquillian.class) public class GreeterTestCase { @Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClasses(Greeter.class, GreeterBean.class); } @EJB private Greeter greeter; @Test public void shouldBeAbleToInvokeEJB() throws Exception { assertEquals("Hello, Earthlings", greeter.greet("Earthlings")); } } 24 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 25. Benefits of Arquillian ● Write less (test) code ● As much or as little “integration” as you need ● Looks like a unit test, but you're in a real environment! ● Easily lookup component to test ● No hesitation when you need a resource ● Run same test in multiple containers ● It's a learning environment 25 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 26. How is a container selected? ● Explain... 26 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 27. Arquillian tactical unit ● Unit testing framework runner ● Deployable test archive ● Test enrichers ● Test run mode ● Target container ● Test framework integrations 27 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 28. Supported unit testing frameworks JUnit TestNG >= 4.8.1 >= 5.12.1 28 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 29. Test archive ● Assembled using ShrinkWrap API ● Declared with static @Deployment method ● Bundles: ● Class/component to test ● Supporting classes ● Configuration and resource files ● Dependent libraries 29 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 30. Micro deployments ● Deploy components in isolation ● Test one functional unit at a time ● Don't need to wait for full application build/startup ● Incremental integration ● Hand pick components & resources ● No “big bang” integration 30 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 31. Test enrichment ● Injection ● Fields & method arguments ● @Inject, @Resource, @EJB, @PersistenceContext, ... ● CDI producer methods in test class ● Context management ● Request & Conversation  Test method ● Session  Test class ● Application  Test class ● More to come... 31 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 32. Test run modes ● In-container ● Test bundled with @Deployment archive ● Archive deployed to container ● Test runs inside container alongside application code ● Test invokes application code directly (same JVM) ● As client ● @Deployment archive is test archive (unmodified) ● Archive deployed to the container ● Test runs in original test runner ● Test interacts as a remote client (e.g., HTTP client) 32 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 33. Classifying the containers ● By mode ● By compliance 33 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 34. Container modes ● Embedded ● Same JVM as test runner ● Test protocol either local or remote ● Lifecycle controlled by Arquillian ● Remote ● Separate JVM from test runner ● Arquillian connects to running container ● Tests executed over remote protocol ● Managed ● Remote with lifecycle management 34 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 35. Container compliance ● Java EE application server (JBoss AS, GlassFish, etc) ● Servlet container (Tomcat, Jetty) ● Managed bean container (Weld SE, Spring) ● OSGi ● Whatever else comes along... 35 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 36. Supported containers ● JBoss AS 5.0 & 5.1 – Managed and remote ● JBoss AS 6 – Managed, remote and embedded ● JBoss JCA – Embedded ● GlassFish 3 – Remote and embedded ● Weld – SE embedded and EE mock embedded ● OpenWebBeans – embedded ● OpenEJB 3.1 – embedded ● OSGi – embedded ● Tomcat 6, Jetty 6.1 and Jetty 7 – embedded ● More on the way... 36 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 37. Container SPI, not just for Java EE public interface DeployableContainer { void setup(Context context, Configuration configuration); void start(Context context) throws LifecycleException; ContainerMethodExecutor deploy(Context context, Archive<?> archive) throws DeploymentException; void undeploy(Context context, Archive<?> archive) throws DeploymentException; void stop(Context context) throws LifecycleException; } 37 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 38. Power tools: test framework integration ● Test frameworks are services too ● Extend component model for tests ● Examples: ● JSFUnit* ● Cobertura ● HTTPUnit ● DBUnit ● Selenium * available 38 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 39. Arquillian... ● is a container-oriented testing framework ● provides a component model for tests ● handles test infrastructure & plumbing ● ships with a set of container implementations ● provides a little bit of magic ;) 39 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 40. Arquillian invasion strategy ● 1.0.0.Alpha3 out! ● More containers ● More framework integrations ● DBUnit, HTTPUnit, Selenium ● Cloud ● Performance extension ● Component coverage ● Package-time bytecode manipulation ● Exception, callback, assertion injection ● Tooling 40 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 41. We're in print! LOOK INSIDE! Enterprise JavaBeans 3.1, Sixth Edition O’Reilly - Andrew Lee Rubinger, et al http://community.jboss.org/groups/oreillyejb6th 41 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 42. Get involved! ● Participate with us! ● Share ideas on the forums (or IRC) ● Give us feedback on releases – still in alpha! ● Fork us! ● http://github.com/arquillian ● Meet us! ● #jbosstesting channel on irc.freenode.net ● Write for us! ● Share your stories – Blog! Tweet! ● Document how it works 42 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen
  • 43. The JBoss Testing Initiative ● Comprehensive testing tool “stack” ● Establish a testing culture in Java EE ● #jbosstesting channel on irc.freenode.net ● Filling voids ● ShrinkWrap – Programmatic archive creation ● Arquillian – Managed integration testing ● JSFUnit – Gray-box JSF testing ● Placeebo – Mock Java EE API implementations ● Descriptors ● Unit testing framework enhancements? 43 Real Java EE Testing: Arquillian and ShrinkWrap | Aslak Knutsen