SlideShare a Scribd company logo
1 of 93
Download to read offline
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.
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.
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.
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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Recently uploaded (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

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.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 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.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 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.
  • 68.
  • 69.
  • 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.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 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