SlideShare a Scribd company logo
1 of 22
Download to read offline
Logo auf dunklen Hintergrund (z.B. Website)




                                             NEEDLE                                for Java EE


                    Need(le)	
  for	
  Speed	
  –	
  Effec<ve	
  Unit	
  Tes<ng	
  hellem Hintergrund
                                                                    Logo auf for	
  Java	
  EE	
  
                                                        	
  
                                         Heinz	
  Wilming,	
  akquinet	
  AG	
  



•    Version	
  2.0	
                          h-p://needle.spree.de/	
  
Mo<va<on	
  



     Why	
  do	
  we	
  Test?	
  
     §      Confidence
     §      Cost	
  Reduc<on	
  
     §      Be-er	
  Design	
  
     §      Documenta<on	
  
     §      Less	
  Debug	
  Time	
  




•      Version	
  2.0	
                    h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  
                                                                  NEEDLE             for Java EE


     The	
  levels	
  of	
  tes0ng	
                              Logo auf dunklen Hintergrund (z.B. Website)




     §  Unit	
                                                   NEEDLE
     §  Integra<on	
                                                                for Java EE


     §  Acceptance	
                                                            Logo auf hellem Hintergrund




     	
  
                                                                  NEEDLE             for Java EE


                                                                                           Logo in Graustufen




                                                                  NEEDLE             for Java EE


                                                                                       Logo in Schwarz/Weiss




•     Version	
  2.0	
               h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Run0me	
  environment	
  




•     Version	
  2.0	
               h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Unit-­‐Test	
  environment	
  




•     Version	
  2.0	
               h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Unit-­‐Test	
  environment	
  



                                                            OrderDao mock =
                                                              mock(OrderDao.class);




                      new ShoppingCart();
•     Version	
  2.0	
                   h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Breaking	
  the	
  encapsula0on	
  
     public class ShoppingCart {

               @Inject
               protected OrderDao orderDao;

               ...

     }




•     Version	
  2.0	
               h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Breaking	
  the	
  encapsula0on	
  
     public class ShoppingCart {

               @Inject
               private OrderDao orderDao;

               ...

     	
  	
  	
  	
  	
  	
  	
  /*	
  
                            	
  	
  	
  *	
  for	
  unit	
  test	
  only	
  
                            	
  	
  	
  */
                                     protected void setOrderDao(OrderDao dao){
                                              orderDao = dao;
                                     }
     }
•     Version	
  2.0	
                h-p://needle.spree.de/	
  
Unit	
  tes<ng	
  



     Using	
  reflec0on	
  
     public class ShoppingCartTest {
             private ShoppingCart shoppingCart;
             private OrderDao mock;
             @Before
             public void setup() throws Exception {
                shoppingCart = new ShoppingCartService();
                mock = mock(OrderDao.class);

                      Field field = ShoppingCart.class.getDeclaredField("orderDao");
                      field.setAccessible(true);
                      field.set(shoppingCart, mock);
             }

             @Test
             public void testCheckout() {
                ...
             }
     }

•        Version	
  2.0	
                      h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  



     Effec0ve	
  Unit	
  Tes0ng	
  for	
  Java	
  EE	
  
     §  out	
  of	
  container	
  tes<ng	
  
     §  test	
  components	
  in	
  isola<on	
  

     §  reduce	
  test	
  setup	
  code	
  
     §  analyze	
  dependencies	
  	
  
         and	
  provide	
  mocks	
  

     §  Fast	
  in	
  development	
  
         and	
  execu<on	
  
•     Version	
  2.0	
            h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  




     public class ShoppingCartTest {

             @Rule
             public NeedleRule needleRule = new NeedleRule();

             @ObjectUnderTest
             private ShoppingCart shoppingCart;

             @Test
             public void testCheckout() {
                boolean checkout = shoppingCart.checkout();
                assertTrue(checkout);
              }
     }

•        Version	
  2.0	
       h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  




     Instan<a<on	
  of	
  @ObjectUnderTest	
  
     Components	
  
     	
  


     Dependency	
  Injec<on	
  
       §  Field	
  
       §  Method	
  
       §  Constuctor	
  
     Default	
  are	
  Mock	
  Objects	
  


•           Version	
  2.0	
      h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  



     Injec0on	
  Provider	
  
     Out-­‐of-­‐the-­‐box	
  
       @Inject, @EJB, @Resource,
       @PersistenceContext,
       @PersistenceUnit
     Configura<on	
  of	
  addi<onal	
  Annota<ons	
  
       §  e.g.	
  Seam	
  2	
  -­‐	
  @In,@Logger 	
  
            	
  


     Configura<on	
  of	
  addi<onal	
  injec<on	
  provider	
  
       §  e.g. javax.inject.Qualifier
•     Version	
  2.0	
        h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  



     Mock	
  injec0on	
  
     public class ShoppingCartTest {

             @Rule
             public NeedleRule needleRule = new NeedleRule();

             @ObjectUnderTest
             private ShoppingCart shoppingCart;

             @Inject
             private OrderDao orderDaoMock;

             @Test
             public void testCheckout() {
               when(orderDaoMock.find(anyLong())).thenReturn(new Order());

                   boolean checkout = shoppingCart.checkout();
                   assertTrue(checkout);
             }
     }
•        Version	
  2.0	
               h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  



     Tes0ng	
  object	
  graphs	
  
     Provide	
  own	
  objects	
  
     	
  


     Mul<ple	
  	
  
     @ObjectUnderTest	
  
     Components	
  
     Wiring	
  complex	
  object	
  graph	
  
     §  @InjectInto
     §  @InjectIntoMany	
  


•           Version	
  2.0	
      h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  



     Database	
  tes0ng	
  
     via	
  JPA	
  Provider,	
  e.g.	
  EclipseLink	
  or	
  Hibernate	
  
     	
  
     	
  


     En<tyManager	
  crea<on	
  and	
  injec<on	
  
     	
  
     	
  


     Op<onal:	
  Execute	
  Database	
  opera<on	
  on	
  test	
  setup	
  
     and	
  teardown	
  	
  
       §  Import	
  SQL	
  Scripts	
  
       §  Dele<ng	
  test	
  data	
  aaer	
  the	
  test	
  execu<on	
  


•           Version	
  2.0	
      h-p://needle.spree.de/	
  
Need(le)	
  for	
  Speed	
  


     public class OrderDaoTest {

            @Rule
            public DatabaseRule dbRule = new DatabaseRule();

            @Rule
            public NeedleRule needleRule = new NeedleRule(dbRule);

            @ObjectUnderTest
            private OrderDao orderDao;

            @Test
            public void testFind() {
              Order order =
                      new OrderTestdataBuilder().buildAndSave();
              Order orderFromDb = orderDao.find(order.getId());
              assertEquals(checkout);
            }
     }
•        Version	
  2.0	
      h-p://needle.spree.de/	
  
Live	
  Demo	
  




                        DEMO	
  
h-p://seam-­‐archetype.sourceforge.net/jbosscc-­‐seam-­‐archetype/1.4/javaee.html	
  
	
   •  Version	
  2.0	
              h-p://needle.spree.de/	
  
Summary	
  



     Summary	
  
     Fast	
  
     Less	
  Glue	
  Code	
  
     Keep	
  Dependencies	
  Private	
  
     Flexible	
  &	
  Extensible	
  	
  
     Developer	
  Happiness	
  ;-­‐)	
  




•     Version	
  2.0	
       h-p://needle.spree.de/	
  
Summary	
  



     Get	
  Started	
  Today!	
  
     <dependency>
       <groupId>de.akquinet.jbosscc</groupId>
       <artifactId>jbosscc-needle</artifactId>
       <version>2.1</version>
       <scope>test</scope>
     </dependency>




•     Version	
  2.0	
     h-p://needle.spree.de/	
  
Links	
  




                                      http://needle.spree.de

                          http://sourceforge.net/projects/jbosscc-needle/

                                   heinz.wilming@akquinet.de

                                     http://blog.akquinet.de/




•    Version	
  2.0	
                      h-p://needle.spree.de/	
  
Logo auf dunklen Hintergrund (z.B. Website)




                          NEEDLE                         for Java EE


                                                    Logo auf hellem Hintergrund




•    Version	
  2.0	
       h-p://needle.spree.de/	
  

More Related Content

What's hot

Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Ryan Mauger
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述fangjiafu
 
Create custom looping procedures in sql server 2005 tech republic
Create custom looping procedures in sql server 2005   tech republicCreate custom looping procedures in sql server 2005   tech republic
Create custom looping procedures in sql server 2005 tech republicKaing Menglieng
 
A JCR View of the World - adaptTo() 2012 Berlin
A JCR View of the World - adaptTo() 2012 BerlinA JCR View of the World - adaptTo() 2012 Berlin
A JCR View of the World - adaptTo() 2012 BerlinAlexander Klimetschek
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)Stephen Chin
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpdayStephan Hochdörfer
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemAlexander Casall
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutDror Helper
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedToru Wonyoung Choi
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)Alexander Casall
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundDataGeekery
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the CloudStephen Chin
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzVictor Rentea
 

What's hot (20)

JavaFX Pitfalls
JavaFX PitfallsJavaFX Pitfalls
JavaFX Pitfalls
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 
Understanding
Understanding Understanding
Understanding
 
Epoxy 介紹
Epoxy 介紹Epoxy 介紹
Epoxy 介紹
 
intellimeet
intellimeetintellimeet
intellimeet
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述
 
Create custom looping procedures in sql server 2005 tech republic
Create custom looping procedures in sql server 2005   tech republicCreate custom looping procedures in sql server 2005   tech republic
Create custom looping procedures in sql server 2005 tech republic
 
A JCR View of the World - adaptTo() 2012 Berlin
A JCR View of the World - adaptTo() 2012 BerlinA JCR View of the World - adaptTo() 2012 Berlin
A JCR View of the World - adaptTo() 2012 Berlin
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
JavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and EcosystemJavaOne - The JavaFX Community and Ecosystem
JavaOne - The JavaFX Community and Ecosystem
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX Mainz
 

Similar to Need(le) for Speed - Effective Unit Testing for Java EE

Wicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWill Hoover
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMark Ginnebaugh
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Anton Arhipov
 
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java GuyGoogle AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java GuyMax Völkel
 
081107 Sammy Eclipse Summit2
081107   Sammy   Eclipse Summit2081107   Sammy   Eclipse Summit2
081107 Sammy Eclipse Summit2mkempka
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?Dmitri Shiryaev
 
Automated Scaling of Microservice Stacks for JavaEE Applications
Automated Scaling of Microservice Stacks for JavaEE ApplicationsAutomated Scaling of Microservice Stacks for JavaEE Applications
Automated Scaling of Microservice Stacks for JavaEE ApplicationsJelastic Multi-Cloud PaaS
 
Developer Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianDeveloper Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianRay Ploski
 
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFish
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFishBatch Applications for Java Platform 1.0: Java EE 7 and GlassFish
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFishArun Gupta
 
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...Peter Pilgrim
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015Alex Theedom
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011Alexander Klimetschek
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 

Similar to Need(le) for Speed - Effective Unit Testing for Java EE (20)

Wicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On Time
 
Microsoft SQL Server Testing Frameworks
Microsoft SQL Server Testing FrameworksMicrosoft SQL Server Testing Frameworks
Microsoft SQL Server Testing Frameworks
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Dao example
Dao exampleDao example
Dao example
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
 
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java GuyGoogle AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
 
081107 Sammy Eclipse Summit2
081107   Sammy   Eclipse Summit2081107   Sammy   Eclipse Summit2
081107 Sammy Eclipse Summit2
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
Automated Scaling of Microservice Stacks for JavaEE Applications
Automated Scaling of Microservice Stacks for JavaEE ApplicationsAutomated Scaling of Microservice Stacks for JavaEE Applications
Automated Scaling of Microservice Stacks for JavaEE Applications
 
Developer Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianDeveloper Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and Arquillian
 
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFish
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFishBatch Applications for Java Platform 1.0: Java EE 7 and GlassFish
Batch Applications for Java Platform 1.0: Java EE 7 and GlassFish
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
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...
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015
 
Js tacktalk team dev js testing performance
Js tacktalk team dev js testing performanceJs tacktalk team dev js testing performance
Js tacktalk team dev js testing performance
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 

More from hwilming

Introduction Machine Learning - Microsoft
Introduction Machine Learning - MicrosoftIntroduction Machine Learning - Microsoft
Introduction Machine Learning - Microsofthwilming
 
A practical introduction to data science and machine learning
A practical introduction to data science and machine learningA practical introduction to data science and machine learning
A practical introduction to data science and machine learninghwilming
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014hwilming
 
Creating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBossCreating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBosshwilming
 
SAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss TechnologiesSAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss Technologieshwilming
 
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7hwilming
 
JBoss EAP clustering
JBoss EAP clustering JBoss EAP clustering
JBoss EAP clustering hwilming
 
JBoss AS / EAP Clustering
JBoss AS / EAP  ClusteringJBoss AS / EAP  Clustering
JBoss AS / EAP Clusteringhwilming
 
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7hwilming
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEhwilming
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungenhwilming
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012hwilming
 
Aerogear Java User Group Presentation
Aerogear Java User Group PresentationAerogear Java User Group Presentation
Aerogear Java User Group Presentationhwilming
 
The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012hwilming
 

More from hwilming (14)

Introduction Machine Learning - Microsoft
Introduction Machine Learning - MicrosoftIntroduction Machine Learning - Microsoft
Introduction Machine Learning - Microsoft
 
A practical introduction to data science and machine learning
A practical introduction to data science and machine learningA practical introduction to data science and machine learning
A practical introduction to data science and machine learning
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
Creating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBossCreating Mobile Enterprise Applications with Red Hat / JBoss
Creating Mobile Enterprise Applications with Red Hat / JBoss
 
SAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss TechnologiesSAP Integration with Red Hat JBoss Technologies
SAP Integration with Red Hat JBoss Technologies
 
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
JavaAktuell - Skalierbare Cluster-Topologien mit dem JBoss AS 7
 
JBoss EAP clustering
JBoss EAP clustering JBoss EAP clustering
JBoss EAP clustering
 
JBoss AS / EAP Clustering
JBoss AS / EAP  ClusteringJBoss AS / EAP  Clustering
JBoss AS / EAP Clustering
 
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
JavaAktuell - Hochverfügbarkeit mit dem JBoss AS 7
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SE
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungen
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
 
Aerogear Java User Group Presentation
Aerogear Java User Group PresentationAerogear Java User Group Presentation
Aerogear Java User Group Presentation
 
The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012The Gear you need to go mobile with Java Enterprise - Jax 2012
The Gear you need to go mobile with Java Enterprise - Jax 2012
 

Need(le) for Speed - Effective Unit Testing for Java EE

  • 1. Logo auf dunklen Hintergrund (z.B. Website) NEEDLE for Java EE Need(le)  for  Speed  –  Effec<ve  Unit  Tes<ng  hellem Hintergrund Logo auf for  Java  EE     Heinz  Wilming,  akquinet  AG   •  Version  2.0   h-p://needle.spree.de/  
  • 2. Mo<va<on   Why  do  we  Test?   §  Confidence §  Cost  Reduc<on   §  Be-er  Design   §  Documenta<on   §  Less  Debug  Time   •  Version  2.0   h-p://needle.spree.de/  
  • 3. Unit  tes<ng   NEEDLE for Java EE The  levels  of  tes0ng   Logo auf dunklen Hintergrund (z.B. Website) §  Unit   NEEDLE §  Integra<on   for Java EE §  Acceptance   Logo auf hellem Hintergrund   NEEDLE for Java EE Logo in Graustufen NEEDLE for Java EE Logo in Schwarz/Weiss •  Version  2.0   h-p://needle.spree.de/  
  • 4. Unit  tes<ng   Run0me  environment   •  Version  2.0   h-p://needle.spree.de/  
  • 5. Unit  tes<ng   Unit-­‐Test  environment   •  Version  2.0   h-p://needle.spree.de/  
  • 6. Unit  tes<ng   Unit-­‐Test  environment   OrderDao mock = mock(OrderDao.class); new ShoppingCart(); •  Version  2.0   h-p://needle.spree.de/  
  • 7. Unit  tes<ng   Breaking  the  encapsula0on   public class ShoppingCart { @Inject protected OrderDao orderDao; ... } •  Version  2.0   h-p://needle.spree.de/  
  • 8. Unit  tes<ng   Breaking  the  encapsula0on   public class ShoppingCart { @Inject private OrderDao orderDao; ...              /*        *  for  unit  test  only        */ protected void setOrderDao(OrderDao dao){ orderDao = dao; } } •  Version  2.0   h-p://needle.spree.de/  
  • 9. Unit  tes<ng   Using  reflec0on   public class ShoppingCartTest { private ShoppingCart shoppingCart; private OrderDao mock; @Before public void setup() throws Exception { shoppingCart = new ShoppingCartService(); mock = mock(OrderDao.class); Field field = ShoppingCart.class.getDeclaredField("orderDao"); field.setAccessible(true); field.set(shoppingCart, mock); } @Test public void testCheckout() { ... } } •  Version  2.0   h-p://needle.spree.de/  
  • 10. Need(le)  for  Speed   Effec0ve  Unit  Tes0ng  for  Java  EE   §  out  of  container  tes<ng   §  test  components  in  isola<on   §  reduce  test  setup  code   §  analyze  dependencies     and  provide  mocks   §  Fast  in  development   and  execu<on   •  Version  2.0   h-p://needle.spree.de/  
  • 11. Need(le)  for  Speed   public class ShoppingCartTest { @Rule public NeedleRule needleRule = new NeedleRule(); @ObjectUnderTest private ShoppingCart shoppingCart; @Test public void testCheckout() { boolean checkout = shoppingCart.checkout(); assertTrue(checkout); } } •  Version  2.0   h-p://needle.spree.de/  
  • 12. Need(le)  for  Speed   Instan<a<on  of  @ObjectUnderTest   Components     Dependency  Injec<on   §  Field   §  Method   §  Constuctor   Default  are  Mock  Objects   •  Version  2.0   h-p://needle.spree.de/  
  • 13. Need(le)  for  Speed   Injec0on  Provider   Out-­‐of-­‐the-­‐box   @Inject, @EJB, @Resource, @PersistenceContext, @PersistenceUnit Configura<on  of  addi<onal  Annota<ons   §  e.g.  Seam  2  -­‐  @In,@Logger     Configura<on  of  addi<onal  injec<on  provider   §  e.g. javax.inject.Qualifier •  Version  2.0   h-p://needle.spree.de/  
  • 14. Need(le)  for  Speed   Mock  injec0on   public class ShoppingCartTest { @Rule public NeedleRule needleRule = new NeedleRule(); @ObjectUnderTest private ShoppingCart shoppingCart; @Inject private OrderDao orderDaoMock; @Test public void testCheckout() { when(orderDaoMock.find(anyLong())).thenReturn(new Order()); boolean checkout = shoppingCart.checkout(); assertTrue(checkout); } } •  Version  2.0   h-p://needle.spree.de/  
  • 15. Need(le)  for  Speed   Tes0ng  object  graphs   Provide  own  objects     Mul<ple     @ObjectUnderTest   Components   Wiring  complex  object  graph   §  @InjectInto §  @InjectIntoMany   •  Version  2.0   h-p://needle.spree.de/  
  • 16. Need(le)  for  Speed   Database  tes0ng   via  JPA  Provider,  e.g.  EclipseLink  or  Hibernate       En<tyManager  crea<on  and  injec<on       Op<onal:  Execute  Database  opera<on  on  test  setup   and  teardown     §  Import  SQL  Scripts   §  Dele<ng  test  data  aaer  the  test  execu<on   •  Version  2.0   h-p://needle.spree.de/  
  • 17. Need(le)  for  Speed   public class OrderDaoTest { @Rule public DatabaseRule dbRule = new DatabaseRule(); @Rule public NeedleRule needleRule = new NeedleRule(dbRule); @ObjectUnderTest private OrderDao orderDao; @Test public void testFind() { Order order = new OrderTestdataBuilder().buildAndSave(); Order orderFromDb = orderDao.find(order.getId()); assertEquals(checkout); } } •  Version  2.0   h-p://needle.spree.de/  
  • 18. Live  Demo   DEMO   h-p://seam-­‐archetype.sourceforge.net/jbosscc-­‐seam-­‐archetype/1.4/javaee.html     •  Version  2.0   h-p://needle.spree.de/  
  • 19. Summary   Summary   Fast   Less  Glue  Code   Keep  Dependencies  Private   Flexible  &  Extensible     Developer  Happiness  ;-­‐)   •  Version  2.0   h-p://needle.spree.de/  
  • 20. Summary   Get  Started  Today!   <dependency> <groupId>de.akquinet.jbosscc</groupId> <artifactId>jbosscc-needle</artifactId> <version>2.1</version> <scope>test</scope> </dependency> •  Version  2.0   h-p://needle.spree.de/  
  • 21. Links   http://needle.spree.de http://sourceforge.net/projects/jbosscc-needle/ heinz.wilming@akquinet.de http://blog.akquinet.de/ •  Version  2.0   h-p://needle.spree.de/  
  • 22. Logo auf dunklen Hintergrund (z.B. Website) NEEDLE for Java EE Logo auf hellem Hintergrund •  Version  2.0   h-p://needle.spree.de/