SlideShare ist ein Scribd-Unternehmen logo
1 von 93
Downloaden Sie, um offline zu lesen
Making Friends with
TDD
John Cleary
Lead Web Developer, DocNet
@TheRealBifter
So, What is TDD?
10 Write one test
20 Run tests (they fail)
30 Write code to make test pass
40 Run tests again (they pass)
50 Refactor (code AND tests)
60 Run test (they still pass)
70 Goto 10
Red
GreenRefactor
Red
GreenRefactor
Write
 a
 failing
 test
Red
GreenRefactor
Write
 a
 failing
 test
Fix
 the
 test
Red
GreenRefactor
Write
 a
 failing
 test
Fix
 the
 test
Make
 it
 pretty
Why do it?
1. Improved Code Design
Classes that are easy to test are by definition decoupled.
1. Improved Code Design
Classes that are easy to test are by definition decoupled.
Encourages refactoring
1. Improved Code Design
2. Verification
Fewer bugs
2. Verification
Fewer bugs
Easier to maintain
2. Verification
Awesome - let’s do it, right?
Awesome - let’s do it, right?
Wait!
Does it take longer?
Does it take longer?
Maybe, maybe not.
Is it harder?
Is it harder?
For sure!
But it wrecks my creativity,
dude?
But it wrecks my creativity,
dude?
Really? Do some prototypes man!
Could we get these benefits
without TDD?
Could we get these benefits
without TDD?
No, but yeah, but no...
Awesome, let's do it!
(for real this time)
Recently Used List Class
Recently Used List Class
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Recently Used List Class
A recently-used-list is initially empty.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Items in the list are unique, so duplicate insertions are moved
rather than added.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Items in the list are unique, so duplicate insertions are moved
rather than added.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Items in the list are unique, so duplicate insertions are moved
rather than added.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Items in the list are unique, so duplicate insertions are moved
rather than added.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Making friends with TDD
Making friends with TDD
Recently Used List Class
A recently-used-list is initially empty.
The most recently added item is first, the least recently added
item is last.
Items can be looked up by index, which counts from zero.
Items in the list are unique, so duplicate insertions are moved
rather than added.
Develop a recently-used-list class to hold strings uniquely in Last-
In-First-Out order.
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Making friends with TDD
Refactor
 to
 this
That wasn’t so hard...
That wasn’t so hard...
...but what about testing the persistence layer?
You’ve got options
Mock the database layer
DBUnit
Codeception
You’ve got options
Mock the database layer
DBUnit
Codeception
You’ve got options
The
 purist
 way
Mock the database layer
DBUnit
Codeception
You’ve got options
The
 purist
 way
The
 easy
 way
Mock the database layer
DBUnit
Codeception
You’ve got options
The
 purist
 way
The

Weitere ähnliche Inhalte

Was ist angesagt?

Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wilddjspiewak
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
Lambda functions in java 8
Lambda functions in java 8Lambda functions in java 8
Lambda functions in java 8James Brown
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functionaldjspiewak
 
Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Gopi Raghavendra
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercisesagorolabs
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full storyJosé Paumard
 
06 Java Language And OOP Part VI
06 Java Language And OOP Part VI06 Java Language And OOP Part VI
06 Java Language And OOP Part VIHari Christian
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java ProgrammersEnno Runne
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpMichael Girouard
 
The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180Mahmoud Samir Fayed
 
Fire in the type hole
Fire in the type holeFire in the type hole
Fire in the type holeihji
 

Was ist angesagt? (20)

Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wild
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Lambda functions in java 8
Lambda functions in java 8Lambda functions in java 8
Lambda functions in java 8
 
Practically Functional
Practically FunctionalPractically Functional
Practically Functional
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
 
Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
 
06 Java Language And OOP Part VI
06 Java Language And OOP Part VI06 Java Language And OOP Part VI
06 Java Language And OOP Part VI
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Java 102
Java 102Java 102
Java 102
 
Java 7 New Features
Java 7 New FeaturesJava 7 New Features
Java 7 New Features
 
The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180
 
Fire in the type hole
Fire in the type holeFire in the type hole
Fire in the type hole
 

Andere mochten auch

What is the Internet (CHS Year 6)
What is the Internet (CHS Year 6)What is the Internet (CHS Year 6)
What is the Internet (CHS Year 6)John Cleary
 
Summary of merging ow and odsp and option paper feb 6 2012
Summary of merging ow and odsp and option paper feb 6 2012Summary of merging ow and odsp and option paper feb 6 2012
Summary of merging ow and odsp and option paper feb 6 2012Bob Vansickle
 
Pfo on sar options paper february 2012(2)
Pfo on sar options paper february 2012(2)Pfo on sar options paper february 2012(2)
Pfo on sar options paper february 2012(2)Bob Vansickle
 
Getting Things Done
Getting Things DoneGetting Things Done
Getting Things DoneJohn Cleary
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the thingsJohn Cleary
 

Andere mochten auch (6)

What is the Internet (CHS Year 6)
What is the Internet (CHS Year 6)What is the Internet (CHS Year 6)
What is the Internet (CHS Year 6)
 
Summary of merging ow and odsp and option paper feb 6 2012
Summary of merging ow and odsp and option paper feb 6 2012Summary of merging ow and odsp and option paper feb 6 2012
Summary of merging ow and odsp and option paper feb 6 2012
 
Pfo on sar options paper february 2012(2)
Pfo on sar options paper february 2012(2)Pfo on sar options paper february 2012(2)
Pfo on sar options paper february 2012(2)
 
User stories
User storiesUser stories
User stories
 
Getting Things Done
Getting Things DoneGetting Things Done
Getting Things Done
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the things
 

Ähnlich wie Making friends with TDD

Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer Gabel
 
Laravelcollectionsunraveled
LaravelcollectionsunraveledLaravelcollectionsunraveled
LaravelcollectionsunraveledRenato Lucena
 
Mastering Python lesson 5a_lists_list_operations
Mastering Python lesson 5a_lists_list_operationsMastering Python lesson 5a_lists_list_operations
Mastering Python lesson 5a_lists_list_operationsRuth Marvin
 
ECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comlechenau124
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-DrivenIan Truslove
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Workhorse Computing
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comledlang1
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comGVlaxmi7
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.comclaric64
 
Rspec Tips
Rspec TipsRspec Tips
Rspec Tipslionpeal
 
Test automation with selenide
Test automation with selenideTest automation with selenide
Test automation with selenideIsuru Madanayaka
 
Ch5 beeing an application
Ch5   beeing an applicationCh5   beeing an application
Ch5 beeing an applicationManolis Vavalis
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigoujaxconf
 

Ähnlich wie Making friends with TDD (20)

TDD Training
TDD TrainingTDD Training
TDD Training
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Laravelcollectionsunraveled
LaravelcollectionsunraveledLaravelcollectionsunraveled
Laravelcollectionsunraveled
 
Mastering Python lesson 5a_lists_list_operations
Mastering Python lesson 5a_lists_list_operationsMastering Python lesson 5a_lists_list_operations
Mastering Python lesson 5a_lists_list_operations
 
ECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.com
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
Beginning linq
Beginning linqBeginning linq
Beginning linq
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Java basics
Java basicsJava basics
Java basics
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.com
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.com
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.com
 
Rspec Tips
Rspec TipsRspec Tips
Rspec Tips
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Test automation with selenide
Test automation with selenideTest automation with selenide
Test automation with selenide
 
Ch5 beeing an application
Ch5   beeing an applicationCh5   beeing an application
Ch5 beeing an application
 
Javasession6
Javasession6Javasession6
Javasession6
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 

Kürzlich hochgeladen

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 

Kürzlich hochgeladen (20)

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 

Making friends with TDD

  • 1. Making Friends with TDD John Cleary Lead Web Developer, DocNet @TheRealBifter
  • 2. So, What is TDD?
  • 3. 10 Write one test 20 Run tests (they fail) 30 Write code to make test pass 40 Run tests again (they pass) 50 Refactor (code AND tests) 60 Run test (they still pass) 70 Goto 10
  • 6.  a
  • 10.  a
  • 13.  the
  • 16.  a
  • 19.  the
  • 21.  it
  • 25. Classes that are easy to test are by definition decoupled. 1. Improved Code Design
  • 26. Classes that are easy to test are by definition decoupled. Encourages refactoring 1. Improved Code Design
  • 29. Fewer bugs Easier to maintain 2. Verification
  • 30. Awesome - let’s do it, right?
  • 31. Awesome - let’s do it, right? Wait!
  • 32. Does it take longer?
  • 33. Does it take longer? Maybe, maybe not.
  • 36. But it wrecks my creativity, dude?
  • 37. But it wrecks my creativity, dude? Really? Do some prototypes man!
  • 38. Could we get these benefits without TDD?
  • 39. Could we get these benefits without TDD? No, but yeah, but no...
  • 40. Awesome, let's do it! (for real this time)
  • 42. Recently Used List Class Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 43. Recently Used List Class A recently-used-list is initially empty. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 44. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 45. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 46. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Items in the list are unique, so duplicate insertions are moved rather than added. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 47. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Items in the list are unique, so duplicate insertions are moved rather than added. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 58. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Items in the list are unique, so duplicate insertions are moved rather than added. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 67. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Items in the list are unique, so duplicate insertions are moved rather than added. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 70. Recently Used List Class A recently-used-list is initially empty. The most recently added item is first, the least recently added item is last. Items can be looked up by index, which counts from zero. Items in the list are unique, so duplicate insertions are moved rather than added. Develop a recently-used-list class to hold strings uniquely in Last- In-First-Out order.
  • 77.  to
  • 79. That wasn’t so hard...
  • 80. That wasn’t so hard... ...but what about testing the persistence layer?
  • 82. Mock the database layer DBUnit Codeception You’ve got options
  • 83. Mock the database layer DBUnit Codeception You’ve got options The
  • 85.  way
  • 86. Mock the database layer DBUnit Codeception You’ve got options The
  • 90.  way
  • 91. Mock the database layer DBUnit Codeception You’ve got options The
  • 98.  way
  • 99. Mock Example function testInsertDatabase() { $insertArray = array( 'name' = 'Miles', ); // create a mock database $mock = $this-getMockBuilder('Zend_Db_Adapter_Pdo_Mysql', array('insert')) -disableOriginalConstructor() -getMock(); // mock out the insert method $mock -expects($this-once()) -method('insert') -with($insertArray); // pass the database to the container $container = new DIContainer(): $container-set('database', $mock); // run the test $user = new User(); $user-setName('Miles'); $user-save(); } Not great because • Requires Dependency Injection • Can be fragile • Complicated But good because • Super fast • Not tied to database structure
  • 100. DBUnit Example public function testCanCreateNewUser() { $user = new User(); $user-setName('Miles'); $user-save(); $queryTable = $this-getConnection()-createTableQuery( 'users', 'SELECT * from users' ); $expectedTable = $this-createFlatXmlDataSet(users-expected.xml) -getTable('users'); $this-assertTableEquals($expectedTable, $queryTable); } Not great because • Slow • Can be fragile • Tied to database structure • Requires xml setup of expected results But good because • Tests are easy to write and read • It’s obvious whats being tested
  • 101. Codeception Example ?php function testSavingUser() { $user = new User(); $user-setName('Miles'); $user-save(); $this-codeGuy-seeInDatabase('users',array('name' = 'Miles')); } ? Not great because • Slow • Tied to database structure But good because • Less fragile than DBUnit (no xml to maintain) • Tests are easy to write and read • It’s obvious whats being tested
  • 103. When testing the DB... Give each developer their own test database (preferably on their own VM)
  • 104. When testing the DB... Give each developer their own test database (preferably on their own VM) DB tests are slow - move them outside the main suite or use memory tables
  • 105. When testing the DB... Give each developer their own test database (preferably on their own VM) DB tests are slow - move them outside the main suite or use memory tables Use a tool like “Migrations” to keep databases in sync
  • 108. UI Testing PHPUnit with Selenium Codeception
  • 109. So, where do we go from here?
  • 110. 1. Have a go www.cyber-dojo.com
  • 111. 2. Build up slowly
  • 112. 2. Build up slowly Start with one afternoon per week
  • 113. 2. Build up slowly Start with one afternoon per week Try pair programming
  • 115. 3. Motivate your team Start a Coding Club / Kata
  • 116. 3. Motivate your team Start a Coding Club / Kata [Get your boss to] buy some books
  • 117. 3. Motivate your team Start a Coding Club / Kata [Get your boss to] buy some books See
  • 118.  me
  • 120.  this
  • 121.  talk
  • 122. 4. Get a CI server Jenkins Travis CruiseControl
  • 125. 5. Share Attend public Katas Forums IRC
  • 127. Thank You John Cleary Lead Web Developer, DocNet @TheRealBifter