SlideShare a Scribd company logo
1 of 40
Download to read offline
Completely Test-Driven
   ian.truslove@nsidc.org
   @iantruslove


  UCAR Software Engineering Assembly, Feb 21, 2012
What’s In It For Me?
•  “So, that TDD sounds great and all, but what
   about <thing>?”
•  See some techniques that really are
   necessary for TDD (and some others that are
   just cool)
•  Start TDD?!
Outline
•    TDD Refresher
•    FIRST: Good Unit Tests
•    For business’s sake, AT!
•    The Test Double family
•    Testing the UI?
•    External resources, aka “What about the DB?”
•    Reality: Legacy Code
•    Wrap-up
TDD Refresher




* Well, almost…
TDD Refresher
Behavior-Driven Development style
  –  (“should” instead of “assert”)
TDD Refresher
TDD Refresher
   Challenges
FIRST: Good Unit Tests
FIRST: Good Unit Tests

       Fast
       Independent
       Repeatable
       Self-verifying
       Timely
FIRST: Good Unit Tests

  Test behaviors, not methods
    –  Don’t test your privates?
FIRST: Good Unit Tests

Each test should test only one thing
  –  One assertion per test?
FIRST: Good Unit Tests

  Only one “real” class per test
    –  Mock the collaborators
    –  But don’t mock values
       (e.g. java.net.URI)
FIRST: Good Unit Tests

  Smell: Test code is hard to read
    –  not enough refactoring
FIRST: Good Unit Tests

Smell: Big ripples of red during changes
  –  not enough refactoring, tests are
     too complex
For business’s sake, AT!
For business’s sake, AT!
•  Acceptance Criteria are specifications for
   what the software needs to do, written in
   domain language, by domain experts.
•  Acceptance Tests (ATs) are executable
   Acceptance Criteria.
•  Unambiguous, executable, repeatable
   specifications and documentation
For business’s sake, AT!


Given {a context}
When {an event occurs}
Then {an observable outcome}
For business’s sake, AT!




   Drive the TDD loop with an AT
For business’s sake, AT!
Cucumber specification:
For business’s sake, AT!
Java step implementations:
For business’s sake, AT!

Smell: ATs with lots of technical details
  –  you’re using ATs instead of UTs,
     or not testing from the outermost
     point of view
For business’s sake, AT!

   Smell: ATs keep breaking
     –  not abstract enough;
        perhaps too imperative
The Test Double family
The Test Double family
The Test Double family
(“Mock object” often means Test Double)

In increasing order of trickiness:
   –  Dummy object
   –  Stub
   –  Mock


this != Meszaros’ xUnit Patterns != Sinon.JS
The Test Double family

Smell: Enormous effort setting up mock
  –  pull the complexity into e.g. domain
     façade objects
The Test Double family

 Smell: Lots of test doubles in a test
   –  poor encapsulation
Testing the UI?
Testing the UI?
Diminishing returns: can you write an
automated test to tell you whether the UI looks
nice? Flows well?


                  Yes, but at what cost?!
Testing the UI?




Prefer unit test over integration test over AT
Testing the UI?

A strategy:
  –  Unit test event handlers
  –  Custom DSLs
  –  Few end-to-end ATs
Testing the UI?
Watir WebDriver – acceptance test
Testing the UI?
JavaScript – unit test
External resources, aka “What
       about the DB?”
External resources, aka “What
       about the DB?”

  Mock it
  Need to mock an interface,
  But I bet there’s no clean
  interface to mock
  ⇒  Adapt: wrap it first!
Reality: Legacy Code
Reality: Legacy Code
•  It’s hard. Don’t start here.
•  Fowler’s Refactoring book – small, safe
   changes
•  Wrap in tests
•  Improve what you touch – “shine a light”
•  100% TDD any new code
•  Feathers’ Legacy Code book
Wrap-up
TDD Getting Started Guide™:
1.    Find a Champion
2.    Hit the books
3.    Go slow
4.    Find your frameworks
5.    New project
6.    Go all-out
7.    Short loops
8.    Refactor Mercilessly
Wrap-up
Things to read:
•  Growing Object-Oriented Software, Guided By Tests - Freeman &
   Pryce
•  Test-Driven Development: By Example – Beck
•  XUnit Test Patterns - Meszaros
•  The RSpec Book - Chelimsky, Astels et al
•  Clean Code: A Handbook of Agile Software Craftsmanship - Uncle
   Bob
•  Test Driven: TDD and Acceptance TDD for Java Developers –
   Lasse Koskela
•  Continuous Delivery - Humble & Farley
•  Refactoring: Improving the Design of Existing Code - Fowler
•  Working Effectively With Legacy Code - Feathers
•  Gojko Adzik’s myriad web papers on automated testing
Questions




                  Online at http://bit.ly/yravMa or
http://dl.dropbox.com/u/4292130/UCAR_SEA_20120221/CompletelyTestDriven.pdf

More Related Content

What's hot

Django strategy-test
Django strategy-testDjango strategy-test
Django strategy-test
Royce Haynes
 
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
Casey Kinsey
 

What's hot (20)

Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
I Don't Test Often ...
I Don't Test Often ...I Don't Test Often ...
I Don't Test Often ...
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introduction
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Staying Ahead of the Curve
Staying Ahead of the CurveStaying Ahead of the Curve
Staying Ahead of the Curve
 
Walking Skeleton
Walking SkeletonWalking Skeleton
Walking Skeleton
 
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014
 
PropErty based testing
PropErty based testingPropErty based testing
PropErty based testing
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databases
 
Test Your Own Stuff - Scrum Atlanta 2015
Test Your Own Stuff - Scrum Atlanta 2015Test Your Own Stuff - Scrum Atlanta 2015
Test Your Own Stuff - Scrum Atlanta 2015
 
Approval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience ReportApproval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience Report
 
Rapid Performance Testing: No Load Generation Required
Rapid Performance Testing: No Load Generation RequiredRapid Performance Testing: No Load Generation Required
Rapid Performance Testing: No Load Generation Required
 
Peer Code Review: In a Nutshell
Peer Code Review: In a NutshellPeer Code Review: In a Nutshell
Peer Code Review: In a Nutshell
 
Sap inside track Munich 2017
Sap inside track Munich 2017Sap inside track Munich 2017
Sap inside track Munich 2017
 
Performance testing ( Approaching , Designing performance tests)
Performance testing ( Approaching , Designing performance tests) Performance testing ( Approaching , Designing performance tests)
Performance testing ( Approaching , Designing performance tests)
 
Test Automation Canvas
Test Automation CanvasTest Automation Canvas
Test Automation Canvas
 
Django strategy-test
Django strategy-testDjango strategy-test
Django strategy-test
 
Europython 2015 Testmon
Europython 2015 TestmonEuropython 2015 Testmon
Europython 2015 Testmon
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD
 
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
 

Viewers also liked

Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
NIMT
 
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัยมว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
NIMT
 
el uso del tiempo en el aula
el uso del  tiempo en el aulael uso del  tiempo en el aula
el uso del tiempo en el aula
stephanie salazar
 
Programa Taller "Uso de las TICs en el Aula de Clases"
Programa Taller "Uso de las TICs en el Aula de Clases"Programa Taller "Uso de las TICs en el Aula de Clases"
Programa Taller "Uso de las TICs en el Aula de Clases"
anitamonina
 
Herramientas tecnológicas en la educación superior
Herramientas tecnológicas en la educación superiorHerramientas tecnológicas en la educación superior
Herramientas tecnológicas en la educación superior
OropezaKolher
 

Viewers also liked (20)

Herramientas en la gestión institución educativa_cipriano_infante
Herramientas en la gestión institución educativa_cipriano_infanteHerramientas en la gestión institución educativa_cipriano_infante
Herramientas en la gestión institución educativa_cipriano_infante
 
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
 
Advanced Debugging Using IntelliTrace
Advanced Debugging Using IntelliTraceAdvanced Debugging Using IntelliTrace
Advanced Debugging Using IntelliTrace
 
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัยมว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
 
Test-driven Development Practices in White Box Test Automation
Test-driven Development Practices in White Box Test AutomationTest-driven Development Practices in White Box Test Automation
Test-driven Development Practices in White Box Test Automation
 
TDD
TDDTDD
TDD
 
Guía de herramientas básicas para la investigación educativa 16-17 unidad 1
Guía de herramientas básicas para la investigación educativa 16-17 unidad 1Guía de herramientas básicas para la investigación educativa 16-17 unidad 1
Guía de herramientas básicas para la investigación educativa 16-17 unidad 1
 
Herramientas de la web 2.0 para trabajo colaborativo
Herramientas de la web 2.0 para trabajo colaborativoHerramientas de la web 2.0 para trabajo colaborativo
Herramientas de la web 2.0 para trabajo colaborativo
 
Presentación en la aplicación en línea prezi y power point.
Presentación en la aplicación en línea prezi y power point.Presentación en la aplicación en línea prezi y power point.
Presentación en la aplicación en línea prezi y power point.
 
Criterios en la selección de tecnología educativa
Criterios en la selección de tecnología educativaCriterios en la selección de tecnología educativa
Criterios en la selección de tecnología educativa
 
Herramientas tic para enseñar y aprender
Herramientas tic para enseñar y aprenderHerramientas tic para enseñar y aprender
Herramientas tic para enseñar y aprender
 
Herramientas web 2.0
Herramientas web 2.0Herramientas web 2.0
Herramientas web 2.0
 
Publicación de contenidos en la Web
Publicación de contenidos en la WebPublicación de contenidos en la Web
Publicación de contenidos en la Web
 
Herramientas educativas web 2.0
Herramientas educativas web 2.0Herramientas educativas web 2.0
Herramientas educativas web 2.0
 
el uso del tiempo en el aula
el uso del  tiempo en el aulael uso del  tiempo en el aula
el uso del tiempo en el aula
 
Programa Taller "Uso de las TICs en el Aula de Clases"
Programa Taller "Uso de las TICs en el Aula de Clases"Programa Taller "Uso de las TICs en el Aula de Clases"
Programa Taller "Uso de las TICs en el Aula de Clases"
 
Herramientas tecnológicas en la educación superior
Herramientas tecnológicas en la educación superiorHerramientas tecnológicas en la educación superior
Herramientas tecnológicas en la educación superior
 
Publicación de presentaciones con herramientas 2.0
Publicación de presentaciones con herramientas 2.0Publicación de presentaciones con herramientas 2.0
Publicación de presentaciones con herramientas 2.0
 
Herramientas educativas
Herramientas educativasHerramientas educativas
Herramientas educativas
 
Aprende a utilizar las herramientas web para la universidad
Aprende a utilizar las herramientas web para la universidadAprende a utilizar las herramientas web para la universidad
Aprende a utilizar las herramientas web para la universidad
 

Similar to Completely Test-Driven

Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 

Similar to Completely Test-Driven (20)

Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
 
Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Bigger Unit Test Are Better
Bigger Unit Test Are BetterBigger Unit Test Are Better
Bigger Unit Test Are Better
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
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
 
Testing smells
Testing smellsTesting smells
Testing smells
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Useful automation
Useful automationUseful automation
Useful automation
 
Testing 101
Testing 101Testing 101
Testing 101
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 

Recently uploaded

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

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Completely Test-Driven

  • 1. Completely Test-Driven ian.truslove@nsidc.org @iantruslove UCAR Software Engineering Assembly, Feb 21, 2012
  • 2. What’s In It For Me? •  “So, that TDD sounds great and all, but what about <thing>?” •  See some techniques that really are necessary for TDD (and some others that are just cool) •  Start TDD?!
  • 3. Outline •  TDD Refresher •  FIRST: Good Unit Tests •  For business’s sake, AT! •  The Test Double family •  Testing the UI? •  External resources, aka “What about the DB?” •  Reality: Legacy Code •  Wrap-up
  • 5. TDD Refresher Behavior-Driven Development style –  (“should” instead of “assert”)
  • 7. TDD Refresher Challenges
  • 9. FIRST: Good Unit Tests Fast Independent Repeatable Self-verifying Timely
  • 10. FIRST: Good Unit Tests Test behaviors, not methods –  Don’t test your privates?
  • 11. FIRST: Good Unit Tests Each test should test only one thing –  One assertion per test?
  • 12. FIRST: Good Unit Tests Only one “real” class per test –  Mock the collaborators –  But don’t mock values (e.g. java.net.URI)
  • 13. FIRST: Good Unit Tests Smell: Test code is hard to read –  not enough refactoring
  • 14. FIRST: Good Unit Tests Smell: Big ripples of red during changes –  not enough refactoring, tests are too complex
  • 16. For business’s sake, AT! •  Acceptance Criteria are specifications for what the software needs to do, written in domain language, by domain experts. •  Acceptance Tests (ATs) are executable Acceptance Criteria. •  Unambiguous, executable, repeatable specifications and documentation
  • 17. For business’s sake, AT! Given {a context} When {an event occurs} Then {an observable outcome}
  • 18. For business’s sake, AT! Drive the TDD loop with an AT
  • 19. For business’s sake, AT! Cucumber specification:
  • 20. For business’s sake, AT! Java step implementations:
  • 21. For business’s sake, AT! Smell: ATs with lots of technical details –  you’re using ATs instead of UTs, or not testing from the outermost point of view
  • 22. For business’s sake, AT! Smell: ATs keep breaking –  not abstract enough; perhaps too imperative
  • 23. The Test Double family
  • 24. The Test Double family
  • 25. The Test Double family (“Mock object” often means Test Double) In increasing order of trickiness: –  Dummy object –  Stub –  Mock this != Meszaros’ xUnit Patterns != Sinon.JS
  • 26. The Test Double family Smell: Enormous effort setting up mock –  pull the complexity into e.g. domain façade objects
  • 27. The Test Double family Smell: Lots of test doubles in a test –  poor encapsulation
  • 29. Testing the UI? Diminishing returns: can you write an automated test to tell you whether the UI looks nice? Flows well? Yes, but at what cost?!
  • 30. Testing the UI? Prefer unit test over integration test over AT
  • 31. Testing the UI? A strategy: –  Unit test event handlers –  Custom DSLs –  Few end-to-end ATs
  • 32. Testing the UI? Watir WebDriver – acceptance test
  • 33. Testing the UI? JavaScript – unit test
  • 34. External resources, aka “What about the DB?”
  • 35. External resources, aka “What about the DB?” Mock it Need to mock an interface, But I bet there’s no clean interface to mock ⇒  Adapt: wrap it first!
  • 37. Reality: Legacy Code •  It’s hard. Don’t start here. •  Fowler’s Refactoring book – small, safe changes •  Wrap in tests •  Improve what you touch – “shine a light” •  100% TDD any new code •  Feathers’ Legacy Code book
  • 38. Wrap-up TDD Getting Started Guide™: 1.  Find a Champion 2.  Hit the books 3.  Go slow 4.  Find your frameworks 5.  New project 6.  Go all-out 7.  Short loops 8.  Refactor Mercilessly
  • 39. Wrap-up Things to read: •  Growing Object-Oriented Software, Guided By Tests - Freeman & Pryce •  Test-Driven Development: By Example – Beck •  XUnit Test Patterns - Meszaros •  The RSpec Book - Chelimsky, Astels et al •  Clean Code: A Handbook of Agile Software Craftsmanship - Uncle Bob •  Test Driven: TDD and Acceptance TDD for Java Developers – Lasse Koskela •  Continuous Delivery - Humble & Farley •  Refactoring: Improving the Design of Existing Code - Fowler •  Working Effectively With Legacy Code - Feathers •  Gojko Adzik’s myriad web papers on automated testing
  • 40. Questions Online at http://bit.ly/yravMa or http://dl.dropbox.com/u/4292130/UCAR_SEA_20120221/CompletelyTestDriven.pdf