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

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...Mozaic Works
 
I Don't Test Often ...
I Don't Test Often ...I Don't Test Often ...
I Don't Test Often ...Gareth Bowles
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introductionSergei Kukharev
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven DevelopmentSarah Dutkiewicz
 
Staying Ahead of the Curve
Staying Ahead of the CurveStaying Ahead of the Curve
Staying Ahead of the CurveTrisha Gee
 
Walking Skeleton
Walking SkeletonWalking Skeleton
Walking Skeletonhepphep
 
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 2014Andrey Rebrov
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databasesChris Skardon
 
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 2015Alex Kell
 
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 Reporthouseofyin
 
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 RequiredTechWell
 
Peer Code Review: In a Nutshell
Peer Code Review: In a NutshellPeer Code Review: In a Nutshell
Peer Code Review: In a NutshellAtlassian
 
Sap inside track Munich 2017
Sap inside track Munich 2017Sap inside track Munich 2017
Sap inside track Munich 2017Rainer Winkler
 
Performance testing ( Approaching , Designing performance tests)
Performance testing ( Approaching , Designing performance tests) Performance testing ( Approaching , Designing performance tests)
Performance testing ( Approaching , Designing performance tests) Abhijeet Patil
 
Test Automation Canvas
Test Automation CanvasTest Automation Canvas
Test Automation CanvasAndrey Rebrov
 
Django strategy-test
Django strategy-testDjango strategy-test
Django strategy-testRoyce Haynes
 
Europython 2015 Testmon
Europython 2015 TestmonEuropython 2015 Testmon
Europython 2015 Testmontib0r
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD Daniel Tracy
 
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 DjangoCasey 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

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_infantecipriano infante
 
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553
Rhythm of time : จังหวะของเวลามหกรรมวิทยาศาสตร์และเทคโนโลยี 2553NIMT
 
Advanced Debugging Using IntelliTrace
Advanced Debugging Using IntelliTraceAdvanced Debugging Using IntelliTrace
Advanced Debugging Using IntelliTraceervinloh
 
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัยมว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัย
มว.เร่งเดินหน้าฟื้นฟูห้องปฏิบัติการสอบเทียบหลังมหาอุทกภัยNIMT
 
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 Automationervinloh
 
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 1Alexis Caltz Segovia
 
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 colaborativoBrisceyda Arce Bojorquez
 
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.CarmenGiselaAcosta
 
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 educativaAlondra Ambrosio
 
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 aprenderNatalie Nobrega Santos
 
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 WebJessica Quinatoa
 
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 aulastephanie 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 superiorOropezaKolher
 
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.0Alegría Blázquez
 
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 universidadGerardo Chunga Chinguel
 

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

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.Malinda Kapuruge
 
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 PerspectiveMalinda Kapuruge
 
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)Rob Reynolds
 
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 StackOverflowAdam Doyle
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with LaravelTyler Johnston
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
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)Dinis Cruz
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentZendCon
 
Bigger Unit Test Are Better
Bigger Unit Test Are BetterBigger Unit Test Are Better
Bigger Unit Test Are BetterPeter Schuler
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
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
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated TestingLars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
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 2014Red Gate Software
 

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

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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
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 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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...
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

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