SlideShare une entreprise Scribd logo
1  sur  11
Coding Dojo - TDD Basics
Steve Zhang
3 Laws of TDD
• First Law: You may not write production code
until you have written a failing unit test.
• Second Law: You may not write more of a
unit test than is sufficient to fail, and not
compiling
• Third Law: You may not write more
production code than is sufficient to pass the
currently
Clean Code, p122 ; Robert Martin
Arrange – Act -Assert
Fake It!
• Fake it till you make it
• Triangulation
“As the tests get more specific, the code gets
more generic.”
- Uncle Bob
Refactoring
• Change code without changing its behavior
• Refactoring != Redesign
• Remove the Fake
• Remove Duplication
• Refactor both test code and production code
F.I.R.S.T. Unit Tests
• Fast
• Independent
• Repeatable
• Self-validating
• Timely
Clean Code, pp 132-133 ; Robert Martin
Test Methods
• Single assert
• No conditional logic
• Standard format
– Setup
– Exercise
– Verify
– Teardown
Recommend Books
Let’s Start!
• Kata: StringCalculator
• Test method Example
add_With_Empty_String_Returns_Zero()

Contenu connexe

En vedette

Grandes cientificos colombianos
Grandes cientificos colombianosGrandes cientificos colombianos
Grandes cientificos colombianos
ximenamacias95
 
Castles by Augusto Sánchez (distancia 2)
Castles by Augusto Sánchez (distancia 2)Castles by Augusto Sánchez (distancia 2)
Castles by Augusto Sánchez (distancia 2)
Paulo Freire
 
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
jl11100
 
Báo cáo thực tập Phân tích tài chính
Báo cáo thực tập Phân tích tài chính Báo cáo thực tập Phân tích tài chính
Báo cáo thực tập Phân tích tài chính
hacuoi
 
The ROI Challenge - Yes, Social Media Can Be Measured!
The ROI Challenge - Yes, Social Media Can Be Measured!The ROI Challenge - Yes, Social Media Can Be Measured!
The ROI Challenge - Yes, Social Media Can Be Measured!
Masterminds Advertising
 
Modernismo y 98 (esquemas)
Modernismo  y 98 (esquemas)Modernismo  y 98 (esquemas)
Modernismo y 98 (esquemas)
joanpedi
 

En vedette (13)

Grandes cientificos colombianos
Grandes cientificos colombianosGrandes cientificos colombianos
Grandes cientificos colombianos
 
Modelling pension reform in illinois
Modelling pension reform in illinoisModelling pension reform in illinois
Modelling pension reform in illinois
 
All About Fossils
All About FossilsAll About Fossils
All About Fossils
 
Recueil2012 13 v25032013
Recueil2012 13 v25032013Recueil2012 13 v25032013
Recueil2012 13 v25032013
 
OGM
OGMOGM
OGM
 
Presentacion sistemas operativos
Presentacion sistemas operativosPresentacion sistemas operativos
Presentacion sistemas operativos
 
Castles by Augusto Sánchez (distancia 2)
Castles by Augusto Sánchez (distancia 2)Castles by Augusto Sánchez (distancia 2)
Castles by Augusto Sánchez (distancia 2)
 
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
Vous n aimez_pas_votre_boulot_vous_allez_l_adorer1
 
Negosiasi kelompok 1
Negosiasi kelompok 1Negosiasi kelompok 1
Negosiasi kelompok 1
 
Báo cáo thực tập Phân tích tài chính
Báo cáo thực tập Phân tích tài chính Báo cáo thực tập Phân tích tài chính
Báo cáo thực tập Phân tích tài chính
 
The ROI Challenge - Yes, Social Media Can Be Measured!
The ROI Challenge - Yes, Social Media Can Be Measured!The ROI Challenge - Yes, Social Media Can Be Measured!
The ROI Challenge - Yes, Social Media Can Be Measured!
 
a sociocultural view of language and learning
a sociocultural view of language and learninga sociocultural view of language and learning
a sociocultural view of language and learning
 
Modernismo y 98 (esquemas)
Modernismo  y 98 (esquemas)Modernismo  y 98 (esquemas)
Modernismo y 98 (esquemas)
 

Similaire à Coding dojo - TDD

Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
Seapine Software
 

Similaire à Coding dojo - TDD (20)

Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introduction
 
Are You Ready For Clean Code?
Are You Ready For Clean Code?Are You Ready For Clean Code?
Are You Ready For Clean Code?
 
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)
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
TDD - Designing with Expectations, not Implementations
TDD - Designing with Expectations, not ImplementationsTDD - Designing with Expectations, not Implementations
TDD - Designing with Expectations, not Implementations
 
Tdd
TddTdd
Tdd
 
An Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven DevelopmentAn Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven Development
 
Clean Code Talk (draft)
Clean Code Talk (draft)Clean Code Talk (draft)
Clean Code Talk (draft)
 
Clean code
Clean codeClean code
Clean code
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
Clean Code (David Frame) - PHPBelfast Meetup 22/02/24
Clean Code (David Frame) - PHPBelfast Meetup 22/02/24Clean Code (David Frame) - PHPBelfast Meetup 22/02/24
Clean Code (David Frame) - PHPBelfast Meetup 22/02/24
 
TDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzzTDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzz
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven DevelopmentABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 

Dernier (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
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...
 
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 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

Coding dojo - TDD

  • 1. Coding Dojo - TDD Basics Steve Zhang
  • 2.
  • 3. 3 Laws of TDD • First Law: You may not write production code until you have written a failing unit test. • Second Law: You may not write more of a unit test than is sufficient to fail, and not compiling • Third Law: You may not write more production code than is sufficient to pass the currently Clean Code, p122 ; Robert Martin
  • 4. Arrange – Act -Assert
  • 5. Fake It! • Fake it till you make it • Triangulation
  • 6. “As the tests get more specific, the code gets more generic.” - Uncle Bob
  • 7. Refactoring • Change code without changing its behavior • Refactoring != Redesign • Remove the Fake • Remove Duplication • Refactor both test code and production code
  • 8. F.I.R.S.T. Unit Tests • Fast • Independent • Repeatable • Self-validating • Timely Clean Code, pp 132-133 ; Robert Martin
  • 9. Test Methods • Single assert • No conditional logic • Standard format – Setup – Exercise – Verify – Teardown
  • 11. Let’s Start! • Kata: StringCalculator • Test method Example add_With_Empty_String_Returns_Zero()

Notes de l'éditeur

  1. Arrange all the things needed to exercise the code Act on the code you want to verify Assert that the code worked as expected
  2. Robert Martin “uncle bob” OO design guru - S.O.L.I.D. principles One of 17 formulator’s of Agile manifesto. Manifesto his idea One founder of “Craftsmanship” movement. Manifesto for Software Craftsmanship. Fast Must be able to run quickly. <10 minutes ideal Independent No test should depend on another. Order should not matter. Repeatable Should be able to run them at any stage, development, QA, production Timely - Created with code
  3. Having a single assert is an ideal. The idea is that the test should test ONLY ONE THING. In practice you might find a couple of asserts are needed, but try to keep it to one.