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 colombianosximenamacias95
 
Modelling pension reform in illinois
Modelling pension reform in illinoisModelling pension reform in illinois
Modelling pension reform in illinoisChristopher Whitaker
 
All About Fossils
All About FossilsAll About Fossils
All About Fossilsgrace_vogel
 
Presentacion sistemas operativos
Presentacion sistemas operativosPresentacion sistemas operativos
Presentacion sistemas operativosAlejoroar08
 
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_adorer1jl11100
 
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
 
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 learningHan Nguyen
 
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

Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDDNacho Cougil
 
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 1Blue Elephant Consulting
 
Test Driven Development - a gentle introduction
Test Driven Development - a gentle introductionTest Driven Development - a gentle introduction
Test Driven Development - a gentle introductionSergei Kukharev
 
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
 
TDD - Designing with Expectations, not Implementations
TDD - Designing with Expectations, not ImplementationsTDD - Designing with Expectations, not Implementations
TDD - Designing with Expectations, not ImplementationsHarshith Shetty
 
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 DevelopmentBlue Elephant Consulting
 
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 ShaonCefalo
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
Tdd practices
Tdd practicesTdd practices
Tdd practicesaxykim00
 
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/24davidgrantframe
 
TDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzzTDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzzRick Liu
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
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 DevelopmentHendrik Neumann
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat
 

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

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
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.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
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.pdfWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
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...kellynguyen01
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Dernier (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
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
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
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...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

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.