SlideShare a Scribd company logo
1 of 17
Download to read offline
1
TDD PracticesTDD Practices
Sang ShinSang Shin
““Code with Passion!”Code with Passion!”
1
2
Topics
• Characteristics of good tests
• What is and why TDD?
• TDD development cycle
• TDD best practices
• TDD anti-patterns
• Testable code best practices
Characteristics ofCharacteristics of
Good TestsGood Tests
4
Characters of Good Tests
• Run fast
> Short setup, run time, tear down
• Run in isolation
> Tests should not rely on data or state created/modified by other tests
> Tests should be able to be reordered
• Use real data whenever possible
> Use copies of production data if possible
• Repeatable
> Should return same result each time it runs
5
Goals for Well-Written Tests
• Readable by others
• Should serve as sample client code for others
• Should serve as a specification (document)
• Should test what they're supposed to test (i.e. that the requirements
have been met) and no more
• Not tightly coupled to the target code
• Should follow good coding principles (single responsibility, etc.)
What is and Why TDD?What is and Why TDD?
7
What is TDD?
• Test-driven development (TDD) is a software development
process that relies on the repetition of a very short development
cycle of Red, Green, Refactor
> As opposed to writing a big chunk of code at a time
• Requirements are turned into very specific test cases, then the
software is improved to pass the new tests only
> As opposed to writing software beyond the requirements
8
Why TDD?
• It helps you focus on design
> “The act of writing a unit test is more an act of design than of
verification. It is also more an act of documentation than of
verification” (Uncle Bob)
• It helps you to think from customer requirements
> The act of writing a unit test closes a remarkable number of
feedback loops
• It helps you to build better written and better tested software
> It helps you to write more testable code
TDD Development CycleTDD Development Cycle
10
TDD Cycle: Red-Green-Refactor
• Repeat the Red-Green-Refactor cycle
> Add failing test (Red)
> Write just enough and simplest possible code to correct the test
failure (Green)
> Refactor code (Refactor)
• For each cycle
> Prefer to add a few new lines of functional code, typically less than
ten, before rerunning tests
> Prefer to limit each TDD cycle to be less than ~2 to ~5 minutes
(could be longer as you become more fluent in TDD)
TDD Best PracticesTDD Best Practices
12
TDD Best Practices
• Only specify what is important
• Make small steps
> Solve things as simply as possible
> Follow ~2 to ~5 minute rule
• Perform refactoring after each passing test
> Don't lose the best opportunity to refactor
• Make testing code expressive and readable
> Testing code should serve as pseudo-documentation
> Example: should_result_this_when_xyz_occurs()
Anti-PatternsAnti-Patterns
14
Examples of Anti-Patterns
• The free ride
> Rather than write a new test method for another feature, a new
assertion rides along an existing test
• The loud mouth
> Clutters up the console with diagnostic messages, logging messages,
and other chatter, even when passing
• The stranger
> A test case that doesn't even belong in the unit tests it's part of. It's
really testing a separate object
• The local hero
> A test case that depends on something specific to the development
environment, passes on one machine, fails on another
Writing Testable CodeWriting Testable Code
Best PracticesBest Practices
16
Writing Testable Code
• Do not use Singleton class unless there is a reason
> It is impossible to mock a Singleton
• Get dependencies to be injected
> Is it impossible to mock the internally created dependencies
17
Code with Passion!Code with Passion!
17

More Related Content

What's hot

Test driven development vs Behavior driven development
Test driven development vs Behavior driven developmentTest driven development vs Behavior driven development
Test driven development vs Behavior driven developmentGallop Solutions
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDDavid Rodenas
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGOAgile Montréal
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief exampleJeremy Kendall
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!Kaizenko
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven DevelopmentViraf Karai
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereDaniel Davis
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Zohirul Alam Tiemoon
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 

What's hot (20)

Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
 
Test driven development vs Behavior driven development
Test driven development vs Behavior driven developmentTest driven development vs Behavior driven development
Test driven development vs Behavior driven development
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief example
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven Development
 
TDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & WhereTDD vs. ATDD - What, Why, Which, When & Where
TDD vs. ATDD - What, Why, Which, When & Where
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 

Similar to Tdd practices

Android tdd
Android tddAndroid tdd
Android tddNhan Cao
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentdcsunu
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDDArati Joshi
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Malinda Kapuruge
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in GolangSofian Hadiwijaya
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Vijay Kumbhar
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 

Similar to Tdd practices (20)

Android tdd
Android tddAndroid tdd
Android tdd
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Tdd
TddTdd
Tdd
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
Test first!
Test first!Test first!
Test first!
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
TDD
TDDTDD
TDD
 

Recently uploaded

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

Tdd practices

  • 1. 1 TDD PracticesTDD Practices Sang ShinSang Shin ““Code with Passion!”Code with Passion!” 1
  • 2. 2 Topics • Characteristics of good tests • What is and why TDD? • TDD development cycle • TDD best practices • TDD anti-patterns • Testable code best practices
  • 4. 4 Characters of Good Tests • Run fast > Short setup, run time, tear down • Run in isolation > Tests should not rely on data or state created/modified by other tests > Tests should be able to be reordered • Use real data whenever possible > Use copies of production data if possible • Repeatable > Should return same result each time it runs
  • 5. 5 Goals for Well-Written Tests • Readable by others • Should serve as sample client code for others • Should serve as a specification (document) • Should test what they're supposed to test (i.e. that the requirements have been met) and no more • Not tightly coupled to the target code • Should follow good coding principles (single responsibility, etc.)
  • 6. What is and Why TDD?What is and Why TDD?
  • 7. 7 What is TDD? • Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle of Red, Green, Refactor > As opposed to writing a big chunk of code at a time • Requirements are turned into very specific test cases, then the software is improved to pass the new tests only > As opposed to writing software beyond the requirements
  • 8. 8 Why TDD? • It helps you focus on design > “The act of writing a unit test is more an act of design than of verification. It is also more an act of documentation than of verification” (Uncle Bob) • It helps you to think from customer requirements > The act of writing a unit test closes a remarkable number of feedback loops • It helps you to build better written and better tested software > It helps you to write more testable code
  • 9. TDD Development CycleTDD Development Cycle
  • 10. 10 TDD Cycle: Red-Green-Refactor • Repeat the Red-Green-Refactor cycle > Add failing test (Red) > Write just enough and simplest possible code to correct the test failure (Green) > Refactor code (Refactor) • For each cycle > Prefer to add a few new lines of functional code, typically less than ten, before rerunning tests > Prefer to limit each TDD cycle to be less than ~2 to ~5 minutes (could be longer as you become more fluent in TDD)
  • 11. TDD Best PracticesTDD Best Practices
  • 12. 12 TDD Best Practices • Only specify what is important • Make small steps > Solve things as simply as possible > Follow ~2 to ~5 minute rule • Perform refactoring after each passing test > Don't lose the best opportunity to refactor • Make testing code expressive and readable > Testing code should serve as pseudo-documentation > Example: should_result_this_when_xyz_occurs()
  • 14. 14 Examples of Anti-Patterns • The free ride > Rather than write a new test method for another feature, a new assertion rides along an existing test • The loud mouth > Clutters up the console with diagnostic messages, logging messages, and other chatter, even when passing • The stranger > A test case that doesn't even belong in the unit tests it's part of. It's really testing a separate object • The local hero > A test case that depends on something specific to the development environment, passes on one machine, fails on another
  • 15. Writing Testable CodeWriting Testable Code Best PracticesBest Practices
  • 16. 16 Writing Testable Code • Do not use Singleton class unless there is a reason > It is impossible to mock a Singleton • Get dependencies to be injected > Is it impossible to mock the internally created dependencies
  • 17. 17 Code with Passion!Code with Passion! 17