SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Logo auf dunklen Hintergrund (z.B. Website)




                            NEEDLE             for Java EE

Effective Unit Testing of Java EE
                                           Logo auf hellem Hintergrund
heinz.wilming@akquinet.de
carsten.erker@akquinet.de
Why do we Test?
•    Confidence
•    Cost Reduction
•    Better Design
•    Documentation
•    Less Debug Time
NEEDLE             for Java EE


         The Levels of Testing
                      Logo auf dunklen Hintergrund (z.B. Website)




•    Unit
                      NEEDLE             for Java EE


•    Integration                     Logo auf hellem Hintergrund




•    Acceptance       NEEDLE             for Java EE
•    Exploratory
                                               Logo in Graustufen




                      NEEDLE             for Java EE


                                           Logo in Schwarz/Weiss
Need(le) for Speed
•  out of container testing
•  test components in isolation
•  reduce test setup code
•  analyze dependencies
   and provide mocks
•  fast in development and
   execution
Needle JUnit Rule to instantiate
       and initialize the objects under test.

Basic Test
       Provides access to dependencies
          of the the objects under test




                 initialized object under test
                     instance with injected
                          dependencies
Needle Testcase
•  Instantiation of @ObjectUnderTest
   Components
•  Dependency Injection
  –  Field
  –  Method
  –  Constuctor
•  Default are Mock Objects
Injection Provider
•  Out-of-the-box
   –  @Inject, @EJB, @Resource,
      @PersistenceContext, @PersistenceUnit

•  Configuration of additional Annotations
   –  e.g. Seam 2
•  Configuration of additional injection provider
   –  e.g. javax.inject.Qualifier
Custom Injection Provider
Custom Injection Provider
1.  NeedleRule




2.  needle.properties
custom.injection.annotations=org.jboss.seam.annot
   ations.In, org.jboss.seam.annotations.Logger

custom.injection.provider.classes=de.akquinet.jud
   con.CurrentUserInjectionProvider
Testing an Object Graph
•  Provide own objects
•  Wiring complex object graph
                      <ObjectUnderTest>
                         Authenticator
                   UserDao
                                          <ObjectUnderTest>
                   Sercurity

@InjectInto
                                              UserDao
                   Logging



@InjectIntoMany
                                               <Mock>
                                                  <Mock>

                      <ObjectUnderTest>
                           Security
Testing an Object Graph
public class AuthenticatorTest {

    @Rule
    public NeedleRule needleRule = new NeedleRule();

    @ObjectUnderTest
    private Authenticator authenticator;

    @ObjectUnderTest
    @InjectInto(targetComponentId=“authenticator“)
    private UserDaoBean userDao;                 <ObjectUnderTest>
                                                            Authenticator
                                                      UserDao
                                                                             <ObjectUnderTest>
    @InjectIntoMany                                   Sercurity
                                                      Logging
                                                                                 UserDao

    private Security security;

    @Test                                                                         <Mock>
    public void test () throws Exception {                                           <Mock>

           ...                                           <ObjectUnderTest>
    }                                                         Security

}
Mock Objects
public class AuthenticatorTest {
                                                                    An EasyMock specific
    @Rule                                                                MockProvider.
    public NeedleRule needleRule = new NeedleRule();
                                                               Inherits from EasyMockSupport.
    @ObjectUnderTest
    private Authenticator authenticator;

    private EasyMockProvider mockProvider = needleRule.getMockProvider();


    @Test
    public void test () throws Exception {
      UserDao userDaoMock = needleRule.getInjectedObject(UserDao.class);

        EasyMock.expect(userDaoMock.find((String)EasyMock.anyObject()));
           ...
        mockProvider.replayAll();

        authenticator.authenticate();                                  Access to injected
                                                                        dependencies.
        mockProvider.verifyAll();

    }
}
Database Testing
•  via JPA Provider, e.g. EclipseLink or
   Hibernate
•  EntityManager creation and injection
•  Transaction Utilities
•  Optional: Execute Database operation
   on test setup and teardown
  –  Import SQL Scripts
  –  Deleting test data after the test execution
Provides access to the
public class UserDaoTest {                               database via JPA.

    @Rule                                         Execute DB Operations
    public DatabaseRule dbRule = new DatabaseRule();

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

    @ObjectUnderTest(implementation = UserDaoBean.class)
    private UserDao userDao;
                                                       Injection Provider of
     @Test                                               the EntityManger
    public void testFind() throws Exception {
      User user = new UserTestdataBuilder(
          dbRule.getEntityManager()).withName("kbeck")
          .buildAndSave();

        User userFromDb = userDao.find("kbeck");          Creates and persist
                                                             an user object
        assertEquals(...);
    }
}
Summary
•    Fast
•    Less Glue Code
•    Keep Dependencies Private
•    Extensible
•    Developer Happiness ;-)
Get Started Today!
<dependency>
  <groupId>de.akquinet.jbosscc</groupId>
  <artifactId>jbosscc-needle</artifactId>
  <version>2.0</version>
  <scope>test</scope>
</dependency>
Logo auf dunklen Hintergrund (z.B. Website)




                                           NEEDLE             for Java EE


                                                          Logo auf hellem Hintergrund




             http://needle.spree.de      NEEDLE
http://sourceforge.net/projects/jbosscc-needle/Java EE
                                             for


                                                                    Logo in Graustufen




          heinz.wilming@akquinet.de
                                           NEEDLE
          carsten.erker@akquinet.de                           for Java EE


                                                                Logo in Schwarz/Weiss




            http://blog.akquinet.de/
Q&A

Mais conteúdo relacionado

Mais procurados

Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetdevlabsalliance
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesNarendra Pathai
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnitinTwentyEight Minutes
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got Better
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got BetterThe Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got Better
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got BetterJustin Hunter
 
JSR-303 Bean Validation API
JSR-303 Bean Validation APIJSR-303 Bean Validation API
JSR-303 Bean Validation APIHeiko Scherrer
 
Unit Testing, TDD and ATDD
Unit Testing, TDD and ATDDUnit Testing, TDD and ATDD
Unit Testing, TDD and ATDDArnon Axelrod
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EEhwilming
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 

Mais procurados (20)

Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Thread & concurrancy
Thread & concurrancyThread & concurrancy
Thread & concurrancy
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnit
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got Better
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got BetterThe Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got Better
The Best Pairwise Testing Tool / Best Orthogonal Array Tool Just Got Better
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
JSR-303 Bean Validation API
JSR-303 Bean Validation APIJSR-303 Bean Validation API
JSR-303 Bean Validation API
 
Unit Testing, TDD and ATDD
Unit Testing, TDD and ATDDUnit Testing, TDD and ATDD
Unit Testing, TDD and ATDD
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Junit
JunitJunit
Junit
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 

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

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
 
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
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Payara
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application DevelopersMichael Heinrichs
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...Otávio Santana
 
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
 
Building stable testing by isolating network layer
Building stable testing by isolating network layerBuilding stable testing by isolating network layer
Building stable testing by isolating network layerJz Chang
 
TDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceTDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceMehdi Valikhani
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAhmed Ehab AbdulAziz
 
Unit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeUnit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeBlueFish
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignJames Phillips
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency InjectionWerner Keil
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 
Unit Testing DFC
Unit Testing DFCUnit Testing DFC
Unit Testing DFCBlueFish
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Roy de Kleijn
 

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

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
 
Robotium Tutorial
Robotium TutorialRobotium Tutorial
Robotium Tutorial
 
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...
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application Developers
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
 
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...
 
Building stable testing by isolating network layer
Building stable testing by isolating network layerBuilding stable testing by isolating network layer
Building stable testing by isolating network layer
 
TDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceTDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With Confidence
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
Unit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes CodeUnit Testing Documentum Foundation Classes Code
Unit Testing Documentum Foundation Classes Code
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency Injection
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
 
Unit Testing DFC
Unit Testing DFCUnit Testing DFC
Unit Testing DFC
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 

Mais de 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
 

Mais de 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
 

Último

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?Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 2024Rafal Los
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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...Martijn de Jong
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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...Neo4j
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (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?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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

  • 1.
  • 2. Logo auf dunklen Hintergrund (z.B. Website) NEEDLE for Java EE Effective Unit Testing of Java EE Logo auf hellem Hintergrund heinz.wilming@akquinet.de carsten.erker@akquinet.de
  • 3.
  • 4. Why do we Test? •  Confidence •  Cost Reduction •  Better Design •  Documentation •  Less Debug Time
  • 5. NEEDLE for Java EE The Levels of Testing Logo auf dunklen Hintergrund (z.B. Website) •  Unit NEEDLE for Java EE •  Integration Logo auf hellem Hintergrund •  Acceptance NEEDLE for Java EE •  Exploratory Logo in Graustufen NEEDLE for Java EE Logo in Schwarz/Weiss
  • 6. Need(le) for Speed •  out of container testing •  test components in isolation •  reduce test setup code •  analyze dependencies and provide mocks •  fast in development and execution
  • 7. Needle JUnit Rule to instantiate and initialize the objects under test. Basic Test Provides access to dependencies of the the objects under test initialized object under test instance with injected dependencies
  • 8. Needle Testcase •  Instantiation of @ObjectUnderTest Components •  Dependency Injection –  Field –  Method –  Constuctor •  Default are Mock Objects
  • 9. Injection Provider •  Out-of-the-box –  @Inject, @EJB, @Resource, @PersistenceContext, @PersistenceUnit •  Configuration of additional Annotations –  e.g. Seam 2 •  Configuration of additional injection provider –  e.g. javax.inject.Qualifier
  • 11. Custom Injection Provider 1.  NeedleRule 2.  needle.properties custom.injection.annotations=org.jboss.seam.annot ations.In, org.jboss.seam.annotations.Logger custom.injection.provider.classes=de.akquinet.jud con.CurrentUserInjectionProvider
  • 12. Testing an Object Graph •  Provide own objects •  Wiring complex object graph <ObjectUnderTest> Authenticator UserDao <ObjectUnderTest> Sercurity @InjectInto UserDao Logging @InjectIntoMany <Mock> <Mock> <ObjectUnderTest> Security
  • 13. Testing an Object Graph public class AuthenticatorTest { @Rule public NeedleRule needleRule = new NeedleRule(); @ObjectUnderTest private Authenticator authenticator; @ObjectUnderTest @InjectInto(targetComponentId=“authenticator“) private UserDaoBean userDao; <ObjectUnderTest> Authenticator UserDao <ObjectUnderTest> @InjectIntoMany Sercurity Logging UserDao private Security security; @Test <Mock> public void test () throws Exception { <Mock> ... <ObjectUnderTest> } Security }
  • 14. Mock Objects public class AuthenticatorTest { An EasyMock specific @Rule MockProvider. public NeedleRule needleRule = new NeedleRule(); Inherits from EasyMockSupport. @ObjectUnderTest private Authenticator authenticator; private EasyMockProvider mockProvider = needleRule.getMockProvider(); @Test public void test () throws Exception { UserDao userDaoMock = needleRule.getInjectedObject(UserDao.class); EasyMock.expect(userDaoMock.find((String)EasyMock.anyObject())); ... mockProvider.replayAll(); authenticator.authenticate(); Access to injected dependencies. mockProvider.verifyAll(); } }
  • 15. Database Testing •  via JPA Provider, e.g. EclipseLink or Hibernate •  EntityManager creation and injection •  Transaction Utilities •  Optional: Execute Database operation on test setup and teardown –  Import SQL Scripts –  Deleting test data after the test execution
  • 16. Provides access to the public class UserDaoTest { database via JPA. @Rule Execute DB Operations public DatabaseRule dbRule = new DatabaseRule(); @Rule public NeedleRule needleRule = new NeedleRule(dbRule); @ObjectUnderTest(implementation = UserDaoBean.class) private UserDao userDao; Injection Provider of @Test the EntityManger public void testFind() throws Exception { User user = new UserTestdataBuilder( dbRule.getEntityManager()).withName("kbeck") .buildAndSave(); User userFromDb = userDao.find("kbeck"); Creates and persist an user object assertEquals(...); } }
  • 17. Summary •  Fast •  Less Glue Code •  Keep Dependencies Private •  Extensible •  Developer Happiness ;-)
  • 18. Get Started Today! <dependency> <groupId>de.akquinet.jbosscc</groupId> <artifactId>jbosscc-needle</artifactId> <version>2.0</version> <scope>test</scope> </dependency>
  • 19. Logo auf dunklen Hintergrund (z.B. Website) NEEDLE for Java EE Logo auf hellem Hintergrund http://needle.spree.de NEEDLE http://sourceforge.net/projects/jbosscc-needle/Java EE for Logo in Graustufen heinz.wilming@akquinet.de NEEDLE carsten.erker@akquinet.de for Java EE Logo in Schwarz/Weiss http://blog.akquinet.de/
  • 20. Q&A