SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Driving Quality with TDD
Steven Mak 麥天志
steven@odd-e.com
www.odd-e.com
Thursday, 6 May 2010
About me
• Steven Mak 麥天志
• Agile Coach at Odd-e
• Lives in Hong Kong
• I do speak Mandarin!
• Agile, TDD Coaching
• Love to code
Thursday, 6 May 2010
Agenda
• Why you care?
• What you can do?
• How to implement?
Thursday, 6 May 2010
Sacrificing quality with
Legacy Code
4
Thursday, 6 May 2010
5
OK, I don’t want Legacy Code
• Don’t write legacy code
• Improve development skills
• Clean up your neighbourhood
• Write both high-level and unit tests
• Raise awareness of the negative impact
Thursday, 6 May 2010
6
Boy Scout Rule
• If we all checked-in our code a little cleaner than
when we checked it out, the code simply could
not rot
Valuecode/designquality
Time
effortneededforchange
Time
Thursday, 6 May 2010
7
What is “testing” anyway?
• What do you need to do before you can ship
your product?
• Simple testing classifications!
– Customer-facing tests, whether the
requirements are fulfilled
– Developer tests, system does what the
developer intended
Thursday, 6 May 2010
8
Professionalism
Thursday, 6 May 2010
Test Driven Development
9
Thursday, 6 May 2010
10
We need Unit Tests
• New Functionality
• Fix problems
• Improve design
• Optimise resources
• “Edit and Pray” or “Cover and Modify”?
Thursday, 6 May 2010
11
Good Unit Tests
• Fast
• Localise problems
• Readable
• One assertion per tests
• Don’t forget higher level/Customer-facing tests
Thursday, 6 May 2010
12
What is not unit tests
• It talks to database
• It communicates across a network
• It touches the file system
• It requires special things to be done in your
environment (e.g. editing configuration files)
Thursday, 6 May 2010
13
Test Driven Development
• 1 Rule
– Only ever write code to fix a failing test
• 3 Steps
– Write a test (which is “red”)
– Code (to make test pass “green”)
– Refactor (test still pass “green”)
Thursday, 6 May 2010
14
What is Refactoring?
• A series of small steps, each of which
changes the program’s internal structure
without changing its external behaviour
Thursday, 6 May 2010
15
Refactoring
• Explain by analogy
– Tidy up at home
– Cleaning hands after surgery
• Refactoring Workbook – Bill Wake
• Aware of code smells
• Relentlessly refactoring
• Any tools available?
• Don’t forget refactoring tests
Thursday, 6 May 2010
16
• Duplicated Code
• Long Method
• Large Struct/Class
• Long parameter list
• Switch statements
• Comments
Code Smells
Thursday, 6 May 2010
17
• No, you still want to do modelling...
• Design workshop
• Model to have a conversations
• Joint design workshops for broader design
issues
• Technical leaders teach at workshops
I heard that we don’t need
modelling with TDD...?
Thursday, 6 May 2010
18
CI is a developer practice
• CI is not merely about a tool
• Encourage splitting changes into small
increments
• TDD fits well with CI practice
• Shaming people has a negative effect
Thursday, 6 May 2010
19
Slow Build?
• Add hardware
• Parallelize
• Change tools
• Incremental Build
• Incremental Deployment
• Manage dependencies
Thursday, 6 May 2010
Can I start on the next
Monday?
20
Thursday, 6 May 2010
21
Convincing your boss
(or yourself)
• Cost of bug fixing is lower if it is found earlier
• In 2008, Case study of TDD at IBM and Microsoft shows
that TDDers enjoy a defect density reduction ranging
from 30% to 90% and a productivity cost of between
15% and 35%
http://research.microsoft.com/en-us/projects/esm/
nagappan_tdd.pdf
• Kent Beck: “If it doesn’t have to work, I can get it done a
lot faster!”
Thursday, 6 May 2010
22
So you want to start?
• Get the team members started writing a few
automated tests before trying to drive their code
with tests
• Spend time working with the team to understand
the real state of the code, the level of
experience of the team members, and how
interested each of them is in making changes to
the way they work
• The team needed to work together to establish a
test strategy and to agree on how they would
organise their tests into a shared suite that
anyone in the team could run
Thursday, 6 May 2010
23
Buy-in from the Team
• It takes time for the team to learn, allow time in
their planning for learning
• Any compelling reasons before they will
commit to making on the extra work of writing
automated tests?
• Most team begins with:
– Write tests for new code and any changes to
existing code
• Discuss with the team and see if they are
committed to do this
• Target of writing a few tests every day
Thursday, 6 May 2010
24
Coding Dojo
Thursday, 6 May 2010
25
A lots of coaching!
• No structure in place to decide when and with
teams to work?
• Internal coaches were asked to do normal
development?
• Not listening to internal coaches?
• Coaching skills not appreciated and further
developed?
• Both internal and external coaching!
Thursday, 6 May 2010
26
Sustaining TDD
• One-line changes accumulate and turn
into legacy code
• Make test coverage more visible
• Look for new areas of their architecture
that they don’t have tests for
– UI?
– Logs?
– Print outs?
Thursday, 6 May 2010
27
Test smells
• Pay attention to the time it takes to build
the application and run the tests
• Watch out for poorly designed tests and
its dependencies
• Isolate long running tests into a separate
test suite that is run in the background
Thursday, 6 May 2010
28
Maintain Test-First Discipline
• Working in pairs to discuss design
• Write automated tests and achieve a
similar level of test coverage as a trial
period
Thursday, 6 May 2010
29
Pair Programming helps
reinforcing test first discipline
• Ping-Pong programming
• Videos of how others do
• Think it aloud
• How Pair Programming Works:
– http://www.computer.org/cms/Computer.org/ComputingNow/homepage/
2010/0110/W_SW_PairProgramming.pdf
Thursday, 6 May 2010
30
No Test tools Available?
• Use Open source unit test frameworks
whenever available
• It is not impossible to write a simple
automated test framework or variant to fit
your needs
Thursday, 6 May 2010
31
Examples of UT frameworks
• C/C++ - CppUTest
• Java - JUnit
• .Net - NUnit
• PHP - PHPUnit
• Python - PyUnit
• Ruby - Test::Unit, RSpec
Thursday, 6 May 2010
32
is TDD only for new projects?
• Identify change points
• Find test points
• Break dependencies
• Write tests
• Make changes and refactor
Thursday, 6 May 2010
33
Fixing Broken Windows
• Talk to the developers individually about
what’s bothering them most to look for
really bad code and it’s too overwhelmed
to clean up
• Help them form a plan of action to
renovate the code
• Recognising the problem and breaking it
down into bite-size pieces
• Collective Code Ownership
Thursday, 6 May 2010
34
I got hardware, can I... ?
• Dual targeting
• Run tests on development environment
• Run tests on real hardware to discover
differences, endian, memory models...
• OS abstraction layer
• Simulation layers
• Lots of stubs, plus dependency injection
• Learning tests
Thursday, 6 May 2010
35
References
Working Effectively with Legacy Code 修改代码的艺术 -
Michael Feathers
Practical TDD and ATDD for Java Developers - Lasse Koskela
Clean Code 代码整洁之道 - Robert Martin
Practices for scaling Agile and Lean practices - Craig Larman
and Bas Vodde
Growing OO Software, guided by tests - Steve Freeman
xUnit Test Patterns - Gerard Meszaros
Agile Coaching - Rachel Davis and Liz Sedley
Thursday, 6 May 2010
36
Questions?
Steven Mak 麥天志
steven@odd-e.com
www.odd-e.com
Thursday, 6 May 2010

Contenu connexe

Tendances

@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPECWojciech Bulaty
 
A Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterA Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterJohn McCaffrey
 
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...UserZoom
 
Building a testing team
Building a testing teamBuilding a testing team
Building a testing teamSQALab
 
New Model Testing: A New Test Process and Tool
New Model Testing:  A New Test Process and ToolNew Model Testing:  A New Test Process and Tool
New Model Testing: A New Test Process and ToolTEST Huddle
 
Atd advanced topicsworkshop
Atd advanced topicsworkshopAtd advanced topicsworkshop
Atd advanced topicsworkshoplisacrispin
 
Testing is Not a 9 to 5 Job - talk by industry executive Mike Lyles
Testing is Not a 9 to 5 Job - talk by industry executive Mike LylesTesting is Not a 9 to 5 Job - talk by industry executive Mike Lyles
Testing is Not a 9 to 5 Job - talk by industry executive Mike LylesApplitools
 
Be More Salmon - Agile Manchester 2016
Be More Salmon - Agile Manchester 2016Be More Salmon - Agile Manchester 2016
Be More Salmon - Agile Manchester 2016Duncan Nisbet
 
Prototyping - the what, why and how at the University of Edinburgh
Prototyping - the what, why and how at the University of EdinburghPrototyping - the what, why and how at the University of Edinburgh
Prototyping - the what, why and how at the University of EdinburghNeil Allison
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven DevelopmentDhaval Shah
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Discover What Your Users Really Think (and what they really do)
Discover What Your Users Really Think (and what they really do)Discover What Your Users Really Think (and what they really do)
Discover What Your Users Really Think (and what they really do)Kristin Valentine
 
RVA QA Meetup #2: The Wild West of Agile QA
RVA QA Meetup #2: The Wild West of Agile QARVA QA Meetup #2: The Wild West of Agile QA
RVA QA Meetup #2: The Wild West of Agile QAFord Prior
 
Product ownership versus product management
Product ownership versus product managementProduct ownership versus product management
Product ownership versus product managementFlavius Stef
 
Help Me, I got a team of junior testers!
Help Me, I got a team of junior testers!Help Me, I got a team of junior testers!
Help Me, I got a team of junior testers!SQALab
 
Exploratory Testing Basics and Future
Exploratory Testing Basics and FutureExploratory Testing Basics and Future
Exploratory Testing Basics and FutureKari Kakkonen
 
What is this exploratory testing thing
What is this exploratory testing thingWhat is this exploratory testing thing
What is this exploratory testing thingtonybruce
 

Tendances (20)

@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC
 
A Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterA Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it better
 
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...
UserZoom Education Series - Research Deep Dive - Advanced - Task-Based TOL (P...
 
Building a testing team
Building a testing teamBuilding a testing team
Building a testing team
 
New Model Testing: A New Test Process and Tool
New Model Testing:  A New Test Process and ToolNew Model Testing:  A New Test Process and Tool
New Model Testing: A New Test Process and Tool
 
10 qa and testing
10 qa and testing10 qa and testing
10 qa and testing
 
Atd advanced topicsworkshop
Atd advanced topicsworkshopAtd advanced topicsworkshop
Atd advanced topicsworkshop
 
Assorted TDD tips
Assorted TDD tipsAssorted TDD tips
Assorted TDD tips
 
Testing is Not a 9 to 5 Job - talk by industry executive Mike Lyles
Testing is Not a 9 to 5 Job - talk by industry executive Mike LylesTesting is Not a 9 to 5 Job - talk by industry executive Mike Lyles
Testing is Not a 9 to 5 Job - talk by industry executive Mike Lyles
 
Be More Salmon - Agile Manchester 2016
Be More Salmon - Agile Manchester 2016Be More Salmon - Agile Manchester 2016
Be More Salmon - Agile Manchester 2016
 
Prototyping - the what, why and how at the University of Edinburgh
Prototyping - the what, why and how at the University of EdinburghPrototyping - the what, why and how at the University of Edinburgh
Prototyping - the what, why and how at the University of Edinburgh
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Discover What Your Users Really Think (and what they really do)
Discover What Your Users Really Think (and what they really do)Discover What Your Users Really Think (and what they really do)
Discover What Your Users Really Think (and what they really do)
 
RVA QA Meetup #2: The Wild West of Agile QA
RVA QA Meetup #2: The Wild West of Agile QARVA QA Meetup #2: The Wild West of Agile QA
RVA QA Meetup #2: The Wild West of Agile QA
 
Product ownership versus product management
Product ownership versus product managementProduct ownership versus product management
Product ownership versus product management
 
Help Me, I got a team of junior testers!
Help Me, I got a team of junior testers!Help Me, I got a team of junior testers!
Help Me, I got a team of junior testers!
 
Exploratory Testing Basics and Future
Exploratory Testing Basics and FutureExploratory Testing Basics and Future
Exploratory Testing Basics and Future
 
What is this exploratory testing thing
What is this exploratory testing thingWhat is this exploratory testing thing
What is this exploratory testing thing
 
QA evolution, in pictures
QA evolution, in picturesQA evolution, in pictures
QA evolution, in pictures
 

En vedette

Explanation by bq. dita mustika rani
Explanation by bq. dita mustika raniExplanation by bq. dita mustika rani
Explanation by bq. dita mustika ranisman 2 mataram
 
Baiq alifia ariestasari narative
Baiq alifia ariestasari narativeBaiq alifia ariestasari narative
Baiq alifia ariestasari narativesman 2 mataram
 
Description of four tree species for private woodland
Description of four tree species for private woodlandDescription of four tree species for private woodland
Description of four tree species for private woodlandsman 2 mataram
 

En vedette (6)

Explanation by bq. dita mustika rani
Explanation by bq. dita mustika raniExplanation by bq. dita mustika rani
Explanation by bq. dita mustika rani
 
Discover WordPress
Discover WordPressDiscover WordPress
Discover WordPress
 
Baiq alifia ariestasari narative
Baiq alifia ariestasari narativeBaiq alifia ariestasari narative
Baiq alifia ariestasari narative
 
Description of four tree species for private woodland
Description of four tree species for private woodlandDescription of four tree species for private woodland
Description of four tree species for private woodland
 
Hortatory 3
Hortatory 3Hortatory 3
Hortatory 3
 
Narrative
NarrativeNarrative
Narrative
 

Similaire à Driving Quality with TDD

A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
DevCoach - Solid Foundations for the New Wave of Software Developers
DevCoach - Solid Foundations for the New Wave of Software DevelopersDevCoach - Solid Foundations for the New Wave of Software Developers
DevCoach - Solid Foundations for the New Wave of Software DevelopersGabriel Tudorica
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
It's XP Stupid (2019)
It's XP Stupid (2019)It's XP Stupid (2019)
It's XP Stupid (2019)Mike Harris
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Dror Helper
 
Lessons learned after 190M lessons served
Lessons learned after 190M lessons servedLessons learned after 190M lessons served
Lessons learned after 190M lessons servedRicardo Bánffy
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
What a DevOps specialist has to know about static code analysis
What a DevOps specialist has to know about static code analysisWhat a DevOps specialist has to know about static code analysis
What a DevOps specialist has to know about static code analysisAndrey Karpov
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreDan Poltawski
 
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...Joshua Ledwell
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
Practical Methods for Adopting DevOps - Michael Stahnke
Practical Methods for Adopting DevOps - Michael StahnkePractical Methods for Adopting DevOps - Michael Stahnke
Practical Methods for Adopting DevOps - Michael StahnkePuppet
 
9 TIPS ON MANAGING IN-HOUSE SEO
9 TIPS ON MANAGING IN-HOUSE SEO 9 TIPS ON MANAGING IN-HOUSE SEO
9 TIPS ON MANAGING IN-HOUSE SEO Allison Fabella
 
Power of the Swarm - Agile Serbia Conference 2017
Power of the Swarm - Agile Serbia Conference 2017Power of the Swarm - Agile Serbia Conference 2017
Power of the Swarm - Agile Serbia Conference 2017Petri Heiramo
 

Similaire à Driving Quality with TDD (20)

A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
TDD in Agile
TDD in AgileTDD in Agile
TDD in Agile
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
DevCoach - Solid Foundations for the New Wave of Software Developers
DevCoach - Solid Foundations for the New Wave of Software DevelopersDevCoach - Solid Foundations for the New Wave of Software Developers
DevCoach - Solid Foundations for the New Wave of Software Developers
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
It's XP Stupid (2019)
It's XP Stupid (2019)It's XP Stupid (2019)
It's XP Stupid (2019)
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012Creating change from within - Agile Practitioners 2012
Creating change from within - Agile Practitioners 2012
 
Lessons learned after 190M lessons served
Lessons learned after 190M lessons servedLessons learned after 190M lessons served
Lessons learned after 190M lessons served
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
What a DevOps specialist has to know about static code analysis
What a DevOps specialist has to know about static code analysisWhat a DevOps specialist has to know about static code analysis
What a DevOps specialist has to know about static code analysis
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
 
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...
Research Ready to Build: Compelling Artefacts that Speak Your Agile Team's La...
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Practical Methods for Adopting DevOps - Michael Stahnke
Practical Methods for Adopting DevOps - Michael StahnkePractical Methods for Adopting DevOps - Michael Stahnke
Practical Methods for Adopting DevOps - Michael Stahnke
 
It's XP, Stupid
It's XP, StupidIt's XP, Stupid
It's XP, Stupid
 
9 TIPS ON MANAGING IN-HOUSE SEO
9 TIPS ON MANAGING IN-HOUSE SEO 9 TIPS ON MANAGING IN-HOUSE SEO
9 TIPS ON MANAGING IN-HOUSE SEO
 
Power of the Swarm - Agile Serbia Conference 2017
Power of the Swarm - Agile Serbia Conference 2017Power of the Swarm - Agile Serbia Conference 2017
Power of the Swarm - Agile Serbia Conference 2017
 

Plus de Steven Mak

Continuous Security Testing
Continuous Security TestingContinuous Security Testing
Continuous Security TestingSteven Mak
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing toolsSteven Mak
 
Adopting technical practices 2013
Adopting technical practices 2013Adopting technical practices 2013
Adopting technical practices 2013Steven Mak
 
100 doors kata solution
100 doors kata solution100 doors kata solution
100 doors kata solutionSteven Mak
 
Bossless companies
Bossless companiesBossless companies
Bossless companiesSteven Mak
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?Steven Mak
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code SmellSteven Mak
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDDSteven Mak
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentSteven Mak
 
Essential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionEssential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionSteven Mak
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in PracticeSteven Mak
 

Plus de Steven Mak (11)

Continuous Security Testing
Continuous Security TestingContinuous Security Testing
Continuous Security Testing
 
Quality comes free with open source testing tools
Quality comes free with open source testing toolsQuality comes free with open source testing tools
Quality comes free with open source testing tools
 
Adopting technical practices 2013
Adopting technical practices 2013Adopting technical practices 2013
Adopting technical practices 2013
 
100 doors kata solution
100 doors kata solution100 doors kata solution
100 doors kata solution
 
Bossless companies
Bossless companiesBossless companies
Bossless companies
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Unbearable Test Code Smell
Unbearable Test Code SmellUnbearable Test Code Smell
Unbearable Test Code Smell
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDD
 
Introduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven DevelopmentIntroduction to Acceptance Test Driven Development
Introduction to Acceptance Test Driven Development
 
Essential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile AdoptionEssential practices and thinking tools for Agile Adoption
Essential practices and thinking tools for Agile Adoption
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in Practice
 

Dernier

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Dernier (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Driving Quality with TDD

  • 1. Driving Quality with TDD Steven Mak 麥天志 steven@odd-e.com www.odd-e.com Thursday, 6 May 2010
  • 2. About me • Steven Mak 麥天志 • Agile Coach at Odd-e • Lives in Hong Kong • I do speak Mandarin! • Agile, TDD Coaching • Love to code Thursday, 6 May 2010
  • 3. Agenda • Why you care? • What you can do? • How to implement? Thursday, 6 May 2010
  • 4. Sacrificing quality with Legacy Code 4 Thursday, 6 May 2010
  • 5. 5 OK, I don’t want Legacy Code • Don’t write legacy code • Improve development skills • Clean up your neighbourhood • Write both high-level and unit tests • Raise awareness of the negative impact Thursday, 6 May 2010
  • 6. 6 Boy Scout Rule • If we all checked-in our code a little cleaner than when we checked it out, the code simply could not rot Valuecode/designquality Time effortneededforchange Time Thursday, 6 May 2010
  • 7. 7 What is “testing” anyway? • What do you need to do before you can ship your product? • Simple testing classifications! – Customer-facing tests, whether the requirements are fulfilled – Developer tests, system does what the developer intended Thursday, 6 May 2010
  • 10. 10 We need Unit Tests • New Functionality • Fix problems • Improve design • Optimise resources • “Edit and Pray” or “Cover and Modify”? Thursday, 6 May 2010
  • 11. 11 Good Unit Tests • Fast • Localise problems • Readable • One assertion per tests • Don’t forget higher level/Customer-facing tests Thursday, 6 May 2010
  • 12. 12 What is not unit tests • It talks to database • It communicates across a network • It touches the file system • It requires special things to be done in your environment (e.g. editing configuration files) Thursday, 6 May 2010
  • 13. 13 Test Driven Development • 1 Rule – Only ever write code to fix a failing test • 3 Steps – Write a test (which is “red”) – Code (to make test pass “green”) – Refactor (test still pass “green”) Thursday, 6 May 2010
  • 14. 14 What is Refactoring? • A series of small steps, each of which changes the program’s internal structure without changing its external behaviour Thursday, 6 May 2010
  • 15. 15 Refactoring • Explain by analogy – Tidy up at home – Cleaning hands after surgery • Refactoring Workbook – Bill Wake • Aware of code smells • Relentlessly refactoring • Any tools available? • Don’t forget refactoring tests Thursday, 6 May 2010
  • 16. 16 • Duplicated Code • Long Method • Large Struct/Class • Long parameter list • Switch statements • Comments Code Smells Thursday, 6 May 2010
  • 17. 17 • No, you still want to do modelling... • Design workshop • Model to have a conversations • Joint design workshops for broader design issues • Technical leaders teach at workshops I heard that we don’t need modelling with TDD...? Thursday, 6 May 2010
  • 18. 18 CI is a developer practice • CI is not merely about a tool • Encourage splitting changes into small increments • TDD fits well with CI practice • Shaming people has a negative effect Thursday, 6 May 2010
  • 19. 19 Slow Build? • Add hardware • Parallelize • Change tools • Incremental Build • Incremental Deployment • Manage dependencies Thursday, 6 May 2010
  • 20. Can I start on the next Monday? 20 Thursday, 6 May 2010
  • 21. 21 Convincing your boss (or yourself) • Cost of bug fixing is lower if it is found earlier • In 2008, Case study of TDD at IBM and Microsoft shows that TDDers enjoy a defect density reduction ranging from 30% to 90% and a productivity cost of between 15% and 35% http://research.microsoft.com/en-us/projects/esm/ nagappan_tdd.pdf • Kent Beck: “If it doesn’t have to work, I can get it done a lot faster!” Thursday, 6 May 2010
  • 22. 22 So you want to start? • Get the team members started writing a few automated tests before trying to drive their code with tests • Spend time working with the team to understand the real state of the code, the level of experience of the team members, and how interested each of them is in making changes to the way they work • The team needed to work together to establish a test strategy and to agree on how they would organise their tests into a shared suite that anyone in the team could run Thursday, 6 May 2010
  • 23. 23 Buy-in from the Team • It takes time for the team to learn, allow time in their planning for learning • Any compelling reasons before they will commit to making on the extra work of writing automated tests? • Most team begins with: – Write tests for new code and any changes to existing code • Discuss with the team and see if they are committed to do this • Target of writing a few tests every day Thursday, 6 May 2010
  • 25. 25 A lots of coaching! • No structure in place to decide when and with teams to work? • Internal coaches were asked to do normal development? • Not listening to internal coaches? • Coaching skills not appreciated and further developed? • Both internal and external coaching! Thursday, 6 May 2010
  • 26. 26 Sustaining TDD • One-line changes accumulate and turn into legacy code • Make test coverage more visible • Look for new areas of their architecture that they don’t have tests for – UI? – Logs? – Print outs? Thursday, 6 May 2010
  • 27. 27 Test smells • Pay attention to the time it takes to build the application and run the tests • Watch out for poorly designed tests and its dependencies • Isolate long running tests into a separate test suite that is run in the background Thursday, 6 May 2010
  • 28. 28 Maintain Test-First Discipline • Working in pairs to discuss design • Write automated tests and achieve a similar level of test coverage as a trial period Thursday, 6 May 2010
  • 29. 29 Pair Programming helps reinforcing test first discipline • Ping-Pong programming • Videos of how others do • Think it aloud • How Pair Programming Works: – http://www.computer.org/cms/Computer.org/ComputingNow/homepage/ 2010/0110/W_SW_PairProgramming.pdf Thursday, 6 May 2010
  • 30. 30 No Test tools Available? • Use Open source unit test frameworks whenever available • It is not impossible to write a simple automated test framework or variant to fit your needs Thursday, 6 May 2010
  • 31. 31 Examples of UT frameworks • C/C++ - CppUTest • Java - JUnit • .Net - NUnit • PHP - PHPUnit • Python - PyUnit • Ruby - Test::Unit, RSpec Thursday, 6 May 2010
  • 32. 32 is TDD only for new projects? • Identify change points • Find test points • Break dependencies • Write tests • Make changes and refactor Thursday, 6 May 2010
  • 33. 33 Fixing Broken Windows • Talk to the developers individually about what’s bothering them most to look for really bad code and it’s too overwhelmed to clean up • Help them form a plan of action to renovate the code • Recognising the problem and breaking it down into bite-size pieces • Collective Code Ownership Thursday, 6 May 2010
  • 34. 34 I got hardware, can I... ? • Dual targeting • Run tests on development environment • Run tests on real hardware to discover differences, endian, memory models... • OS abstraction layer • Simulation layers • Lots of stubs, plus dependency injection • Learning tests Thursday, 6 May 2010
  • 35. 35 References Working Effectively with Legacy Code 修改代码的艺术 - Michael Feathers Practical TDD and ATDD for Java Developers - Lasse Koskela Clean Code 代码整洁之道 - Robert Martin Practices for scaling Agile and Lean practices - Craig Larman and Bas Vodde Growing OO Software, guided by tests - Steve Freeman xUnit Test Patterns - Gerard Meszaros Agile Coaching - Rachel Davis and Liz Sedley Thursday, 6 May 2010