SlideShare uma empresa Scribd logo
1 de 27
Test Driven Development
       Demonstrated
             Alan Christensen @christensena
              Tom Gutteridge @trgutteridge


A g ile P r o f e s s io n a ls N e t w o r k
            C h r is t c h u r c h
   Th a n k s to o u r s p o n s o r s …
2
Who am I?
Format
• Introduction Presentation
• Live coding exercise
• Review slides
• TDD in the real world
• Questions and discussion
Test Driven
                  Development
•   It is a development technique

•   Incremental (iterative) workflow

    •   Always write a failing test
        first (red)

    •   Only write the minimum
        code to pass the failing test
        (green)

    •   Improve code while all tests
        are passing (refactor)          http://www.agileapps.co.uk/methodology/continuous.html
Not about testing #1
• Yes you do end up with a suite of tests
• But TDD is a development exercise
 • my mindset is coding, not testing
 • I will not be exhausting edge cases, etc
    (at least initially)
Not about testing #2
• By practicing TDD
 • I approach my code from the outside,
    focusing on specifying behaviour
 • I can focus on one thing at a time
 • My resulting code is inherently designed
    for testability
 • I get fast feedback
Live coding exercise

• Coding Kata
• Wikipedia definition: “A code kata is an
  exercise in programming which helps hone
  your skills through practice and repetition”
TDD improves design
• Encourages separation of concerns/single
  responsibility principle (SRP)
• Incremental, iterative: can lead to simpler
  designs
• Reduces fear of refactoring, encouraging
  improvements to design
• Alerts me to design smells
Tests as documentation

• Unit test code provides numerous working
  examples of API usage
• Good unit test structure and naming can
  act as a specification
• Tests as documentation always up to date
  (or the tests are failing)
Objections to TDD
• It takes too much time
• Tests can make it harder to refactor, not
  easier
• It’s just too hard with our legacy code or
  un-mockable framework(s)
• Our test suite takes too long to run so we
  don’t run it very often
Why is TDD Hard?
• Mindset seems unnatural at first
• Many frameworks/library components
  make it difficult to verify behaviour
• Large monolithic blocks of legacy code are
  hard to isolate
• Good design is not always obvious at first
• Forgetting to test first, not afterwards!
Make TDD easier
• Practice Red-Green-Refactor discipline on
  simpler examples (e.g. katas) away from a
  real code base
• Learn from each other (e.g. weekly brown
  bag/dojo sessions), pair programming
• Learn good design, especially OO design
• Listen to your tests! If it’s getting hard
  going, consider refactoring your code
• Take it seriously!
Tips: Untestable
        Frameworks
• Use adapter pattern to "broker" untestable
  dependencies
• Adapters should be tailored to how they
  are used by the app. Adapters do not need
  to expose entire API, only what is needed
• Decouple logic from frameworks (e.g. use
  MVC pattern)
Productivity with TDD
• It takes practice to become productive
• Test code should be taken seriously, not
  treated as throwaway
• Keep duplication to a minimum but balance
  this with readability
• Worst case: your design completely
  changes resulting in rewrite. You have the
  old tests as a reference (specs)
What not to TDD?
What is a unit?

• "smallest thing that makes sense" George
  Dinwiddie
• Sometimes a method, sometimes a
  collaboration of classes
Unit vs Integration
• Unit tests
 • should be fast (fast feedback loop)
 • should be focused
 • when they fail, they usually point you to
    where problem is
  • rigorous within the component under
    test
  • one assert per test
Integration vs Unit
• Integration tests
 • usually slow
 • good for verifying unit tested
    components connect together properly
  • good for acceptance tests
  • often easier to start with on a legacy
    code base
Other Topics
• System Under Test isolation (mocks and
  stubs)
• Real World Unit Testing (or how to deal
  with existing test unfriendly code)
• Context specification (or how to write
  expressive, DRY test suites)
• Tips and Tricks, avoiding anti-patterns
Links

• String Calculator kata exercise
  http://osherove.com/tdd-kata-1/
• Bowling game kata step by step
  (Powerpoint)
  http://butunclebob.com/ArticleS.UncleBob.TheBow

Mais conteúdo relacionado

Mais procurados

Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesMozaic Works
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Zohirul Alam Tiemoon
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereDaniel Davis
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?Steven Mak
 
Clean code - Getting your R&D on board
Clean code - Getting your R&D on boardClean code - Getting your R&D on board
Clean code - Getting your R&D on boardRuth Sperer
 
Intro TDD Portuguese developers meetup London 16/04/2014
Intro TDD Portuguese developers meetup London 16/04/2014Intro TDD Portuguese developers meetup London 16/04/2014
Intro TDD Portuguese developers meetup London 16/04/2014Pedro Santos
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect coupleStephen Tucker
 
Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests EffectivelyPaul Boocock
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Value of Unit Testing
Value of Unit TestingValue of Unit Testing
Value of Unit TestingFerose Khan J
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDDArati Joshi
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
Lập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentLập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentAnh Lê
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
Software craftmanship coaching
Software craftmanship coachingSoftware craftmanship coaching
Software craftmanship coachingPedro Santos
 

Mais procurados (20)

Alexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the TrenchesAlexandru Bolboaca - Unit Testing from the Trenches
Alexandru Bolboaca - Unit Testing from the Trenches
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & Where
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Clean code - Getting your R&D on board
Clean code - Getting your R&D on boardClean code - Getting your R&D on board
Clean code - Getting your R&D on board
 
TDD and Getting Paid
TDD and Getting PaidTDD and Getting Paid
TDD and Getting Paid
 
Intro TDD Portuguese developers meetup London 16/04/2014
Intro TDD Portuguese developers meetup London 16/04/2014Intro TDD Portuguese developers meetup London 16/04/2014
Intro TDD Portuguese developers meetup London 16/04/2014
 
Agile and ATDD the perfect couple
Agile and ATDD the perfect coupleAgile and ATDD the perfect couple
Agile and ATDD the perfect couple
 
Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests Effectively
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Value of Unit Testing
Value of Unit TestingValue of Unit Testing
Value of Unit Testing
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Lập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentLập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven development
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Agile test
Agile testAgile test
Agile test
 
Software craftmanship coaching
Software craftmanship coachingSoftware craftmanship coaching
Software craftmanship coaching
 

Destaque

Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD DemonstratedAlan Christensen
 
Code Katas Spring 2012
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012Mike Clement
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Alan Christensen
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignÜrgo Ringo
 
Log Classification in the Hardwood Timber Industry: Method and Value Analysis
Log Classification in the Hardwood Timber Industry: Method and Value AnalysisLog Classification in the Hardwood Timber Industry: Method and Value Analysis
Log Classification in the Hardwood Timber Industry: Method and Value AnalysisAlvaro Gil
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Destaque (8)

Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
Code Katas Spring 2012
Code Katas Spring 2012Code Katas Spring 2012
Code Katas Spring 2012
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Log Classification in the Hardwood Timber Industry: Method and Value Analysis
Log Classification in the Hardwood Timber Industry: Method and Value AnalysisLog Classification in the Hardwood Timber Industry: Method and Value Analysis
Log Classification in the Hardwood Timber Industry: Method and Value Analysis
 
Séminaire Log Management
Séminaire Log ManagementSéminaire Log Management
Séminaire Log Management
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Semelhante a TDD - Christchurch APN May 2012

TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)Ahmed Misbah
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDDAhmed Misbah
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
Tdd practices
Tdd practicesTdd practices
Tdd practicesaxykim00
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Dror Helper
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven DevelopmentSiva Arunachalam
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)Peter Kofler
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
The problem with tdd
The problem with tddThe problem with tdd
The problem with tddDror Helper
 

Semelhante a TDD - Christchurch APN May 2012 (20)

TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)TDD Anti-patterns (2022 edition)
TDD Anti-patterns (2022 edition)
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
It's XP, Stupid
It's XP, StupidIt's XP, Stupid
It's XP, Stupid
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
TDD in Agile
TDD in AgileTDD in Agile
TDD in Agile
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
The problem with tdd
The problem with tddThe problem with tdd
The problem with tdd
 

Último

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Último (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

TDD - Christchurch APN May 2012

  • 1. Test Driven Development Demonstrated Alan Christensen @christensena Tom Gutteridge @trgutteridge A g ile P r o f e s s io n a ls N e t w o r k C h r is t c h u r c h Th a n k s to o u r s p o n s o r s …
  • 2. 2
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 10. Format • Introduction Presentation • Live coding exercise • Review slides • TDD in the real world • Questions and discussion
  • 11. Test Driven Development • It is a development technique • Incremental (iterative) workflow • Always write a failing test first (red) • Only write the minimum code to pass the failing test (green) • Improve code while all tests are passing (refactor) http://www.agileapps.co.uk/methodology/continuous.html
  • 12. Not about testing #1 • Yes you do end up with a suite of tests • But TDD is a development exercise • my mindset is coding, not testing • I will not be exhausting edge cases, etc (at least initially)
  • 13. Not about testing #2 • By practicing TDD • I approach my code from the outside, focusing on specifying behaviour • I can focus on one thing at a time • My resulting code is inherently designed for testability • I get fast feedback
  • 14. Live coding exercise • Coding Kata • Wikipedia definition: “A code kata is an exercise in programming which helps hone your skills through practice and repetition”
  • 15. TDD improves design • Encourages separation of concerns/single responsibility principle (SRP) • Incremental, iterative: can lead to simpler designs • Reduces fear of refactoring, encouraging improvements to design • Alerts me to design smells
  • 16. Tests as documentation • Unit test code provides numerous working examples of API usage • Good unit test structure and naming can act as a specification • Tests as documentation always up to date (or the tests are failing)
  • 17. Objections to TDD • It takes too much time • Tests can make it harder to refactor, not easier • It’s just too hard with our legacy code or un-mockable framework(s) • Our test suite takes too long to run so we don’t run it very often
  • 18. Why is TDD Hard? • Mindset seems unnatural at first • Many frameworks/library components make it difficult to verify behaviour • Large monolithic blocks of legacy code are hard to isolate • Good design is not always obvious at first • Forgetting to test first, not afterwards!
  • 19. Make TDD easier • Practice Red-Green-Refactor discipline on simpler examples (e.g. katas) away from a real code base • Learn from each other (e.g. weekly brown bag/dojo sessions), pair programming • Learn good design, especially OO design • Listen to your tests! If it’s getting hard going, consider refactoring your code • Take it seriously!
  • 20. Tips: Untestable Frameworks • Use adapter pattern to "broker" untestable dependencies • Adapters should be tailored to how they are used by the app. Adapters do not need to expose entire API, only what is needed • Decouple logic from frameworks (e.g. use MVC pattern)
  • 21. Productivity with TDD • It takes practice to become productive • Test code should be taken seriously, not treated as throwaway • Keep duplication to a minimum but balance this with readability • Worst case: your design completely changes resulting in rewrite. You have the old tests as a reference (specs)
  • 22. What not to TDD?
  • 23. What is a unit? • "smallest thing that makes sense" George Dinwiddie • Sometimes a method, sometimes a collaboration of classes
  • 24. Unit vs Integration • Unit tests • should be fast (fast feedback loop) • should be focused • when they fail, they usually point you to where problem is • rigorous within the component under test • one assert per test
  • 25. Integration vs Unit • Integration tests • usually slow • good for verifying unit tested components connect together properly • good for acceptance tests • often easier to start with on a legacy code base
  • 26. Other Topics • System Under Test isolation (mocks and stubs) • Real World Unit Testing (or how to deal with existing test unfriendly code) • Context specification (or how to write expressive, DRY test suites) • Tips and Tricks, avoiding anti-patterns
  • 27. Links • String Calculator kata exercise http://osherove.com/tdd-kata-1/ • Bowling game kata step by step (Powerpoint) http://butunclebob.com/ArticleS.UncleBob.TheBow