SlideShare a Scribd company logo
Dependency Injection and Testing with the Spring framework




                     Leonardo Borges ­ www.leonardoborges.com
                                         
Dependency Injection and Testing with the Spring framework



    
        Why dependency injection?
        
            It frees your code of knowing about the underlying 
            implementation
        
            Eliminates the necessity of lookup codes, thus 
            saving development time
        
            Eases the testing environment

                                   
Dependency Injection and Testing with the Spring framework



    
        A first example




                                
Dependency Injection and Testing with the Spring framework



    
        Testing the Service class




                                
Dependency Injection and Testing with the Spring framework



    
        Great! A JDBC DAO! But I was planning to 
        use Hibernate!
        
            Problem
             
                 The service object knows the DAO's implementation 
                 class
        
            Solution
             
                 Make the DAO classes implement an interface
                                       
Dependency Injection and Testing with the Spring framework



    
        The new DAO classes




                                
Dependency Injection and Testing with the Spring framework



    
        But to achieve independency, we need to 
        change the service class




                                
Dependency Injection and Testing with the Spring framework



    
        Dependency Injection kicks in




                                
Dependency Injection and Testing with the Spring framework



    
        It's all about context




                                  
Dependency Injection and Testing with the Spring framework



    
        Testing the new Service class




                                
Dependency Injection and Testing with the Spring framework



    
        It's all about [test] context




                                 
Dependency Injection and Testing with the Spring framework



    
        Results from testing the new Service class




                                
Dependency Injection and Testing with the Spring framework



    
        Conclusions
        
            With dependency injection and spring, you can 
            achieve a great level of independence while 
            keeping your code highly testable trough the easy 
            substitution of your real objects by mocks.




                                  
Dependency Injection and Testing with the Spring framework



    
        Further Resources
        
            www.springframework.org
        
            www.leonardoborges.com




                                

More Related Content

What's hot (12)

PPTX
TDD in functional testing with WebDriver
Mikalai Alimenkou
 
PPTX
Continuous Integration in Action
Boris Modylevsky
 
PPTX
Automated testing - how?
Markko Paas
 
PDF
An Introduction to Dependency Injection
Adam Stephensen
 
PDF
Test Automation and Innovation with Open Source Tools
Michael Palotas
 
PDF
Keyword Driven Testing
Maveryx
 
PPTX
ATAGTR2017 Upgrading a mobile tester's weapons with advanced debugging
Agile Testing Alliance
 
PDF
Lap around visual studio alm 2013
Angela Dugan
 
PPTX
Unit & integration testing
Pavlo Hodysh
 
PDF
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
Michael Kuehne-Schlinkert
 
PDF
Reduce Reuse Refactor
Alena Holligan
 
PPTX
Seeding a Tree in a Gherkin
Paul Rohorzka
 
TDD in functional testing with WebDriver
Mikalai Alimenkou
 
Continuous Integration in Action
Boris Modylevsky
 
Automated testing - how?
Markko Paas
 
An Introduction to Dependency Injection
Adam Stephensen
 
Test Automation and Innovation with Open Source Tools
Michael Palotas
 
Keyword Driven Testing
Maveryx
 
ATAGTR2017 Upgrading a mobile tester's weapons with advanced debugging
Agile Testing Alliance
 
Lap around visual studio alm 2013
Angela Dugan
 
Unit & integration testing
Pavlo Hodysh
 
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
Michael Kuehne-Schlinkert
 
Reduce Reuse Refactor
Alena Holligan
 
Seeding a Tree in a Gherkin
Paul Rohorzka
 

Similar to Testing with Spring (20)

PPTX
Spring framework & inversion of control
Nazim Sitmanbetov
 
PPTX
PRESENTATION_CHAABA_AYOUB_ING5_ISI.pptx
MoulayAyoubChaaba
 
PPTX
Introduction to Spring Framework
ASG
 
PPTX
Dependency injection and inversion
chhabraravish23
 
PPTX
Walk in the shoe of angular
Fiyaz Hasan
 
PPT
Dependency Injection & IoC
Dennis Loktionov
 
PPTX
Software reengineering for Developers
Bradley Irby
 
PPTX
Coding Naked
Caleb Jenkins
 
PPTX
Growing Trends of Open Source UI Frameworks
SmartBear
 
PDF
Unit Testing Fundamentals
Richard Paul
 
PPTX
Test Smarter Not Harder - how to design tests for continuous delivery
Melissa Benua
 
PDF
Swiz DAO
devaraj ns
 
PPTX
ITB 2023 Build Vue Apps Using tdd (Test-Driven Development).pptx
Ortus Solutions, Corp
 
PPTX
Dependency Inversion Principle
Shahriar Hyder
 
PPTX
Introduction To MacWire
Knoldus Inc.
 
PPTX
Dependency Injection
Alastair Smith
 
PDF
Microservices Testing at Scale
VMware Tanzu
 
PDF
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
UA Mobile
 
PPTX
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy
 
PDF
Real World Dependency Injection - PFCongres 2010
Stephan Hochdörfer
 
Spring framework & inversion of control
Nazim Sitmanbetov
 
PRESENTATION_CHAABA_AYOUB_ING5_ISI.pptx
MoulayAyoubChaaba
 
Introduction to Spring Framework
ASG
 
Dependency injection and inversion
chhabraravish23
 
Walk in the shoe of angular
Fiyaz Hasan
 
Dependency Injection & IoC
Dennis Loktionov
 
Software reengineering for Developers
Bradley Irby
 
Coding Naked
Caleb Jenkins
 
Growing Trends of Open Source UI Frameworks
SmartBear
 
Unit Testing Fundamentals
Richard Paul
 
Test Smarter Not Harder - how to design tests for continuous delivery
Melissa Benua
 
Swiz DAO
devaraj ns
 
ITB 2023 Build Vue Apps Using tdd (Test-Driven Development).pptx
Ortus Solutions, Corp
 
Dependency Inversion Principle
Shahriar Hyder
 
Introduction To MacWire
Knoldus Inc.
 
Dependency Injection
Alastair Smith
 
Microservices Testing at Scale
VMware Tanzu
 
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
UA Mobile
 
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy
 
Real World Dependency Injection - PFCongres 2010
Stephan Hochdörfer
 
Ad

More from Leonardo Borges (20)

PDF
Realtime collaboration with Clojure - EuroClojure - Barcelona, 2015
Leonardo Borges
 
PDF
Parametricity - #cljsyd - May, 2015
Leonardo Borges
 
PDF
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
PDF
The algebra of library design
Leonardo Borges
 
PDF
Futures e abstração - QCon São Paulo 2015
Leonardo Borges
 
PDF
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
 
PDF
High Performance web apps in Om, React and ClojureScript
Leonardo Borges
 
PDF
Programação functional reativa: lidando com código assíncrono
Leonardo Borges
 
PDF
Monads in Clojure
Leonardo Borges
 
PDF
Clojure Macros Workshop: LambdaJam 2013 / CUFP 2013
Leonardo Borges
 
PDF
Intro to Clojure's core.async
Leonardo Borges
 
PDF
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
PDF
Clojure/West 2013 in 30 mins
Leonardo Borges
 
PDF
Clojure Reducers / clj-syd Aug 2012
Leonardo Borges
 
PDF
The many facets of code reuse in JavaScript
Leonardo Borges
 
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
PDF
Heroku addons development - Nov 2011
Leonardo Borges
 
PDF
Clouds against the Floods (RubyConfBR2011)
Leonardo Borges
 
KEY
Clouds Against the Floods
Leonardo Borges
 
KEY
Arel in Rails 3
Leonardo Borges
 
Realtime collaboration with Clojure - EuroClojure - Barcelona, 2015
Leonardo Borges
 
Parametricity - #cljsyd - May, 2015
Leonardo Borges
 
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
The algebra of library design
Leonardo Borges
 
Futures e abstração - QCon São Paulo 2015
Leonardo Borges
 
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
 
High Performance web apps in Om, React and ClojureScript
Leonardo Borges
 
Programação functional reativa: lidando com código assíncrono
Leonardo Borges
 
Monads in Clojure
Leonardo Borges
 
Clojure Macros Workshop: LambdaJam 2013 / CUFP 2013
Leonardo Borges
 
Intro to Clojure's core.async
Leonardo Borges
 
Functional Reactive Programming in Clojurescript
Leonardo Borges
 
Clojure/West 2013 in 30 mins
Leonardo Borges
 
Clojure Reducers / clj-syd Aug 2012
Leonardo Borges
 
The many facets of code reuse in JavaScript
Leonardo Borges
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
Heroku addons development - Nov 2011
Leonardo Borges
 
Clouds against the Floods (RubyConfBR2011)
Leonardo Borges
 
Clouds Against the Floods
Leonardo Borges
 
Arel in Rails 3
Leonardo Borges
 
Ad

Recently uploaded (20)

PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 

Testing with Spring