SlideShare une entreprise Scribd logo
1  sur  13
THE THREE 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 IS FAILING.
• THIRD LAW YOU MAY NOT WRITE MORE PRODUCTION CODE THAN IS SUFFICIENT TO PASS THE
CURRENTLY FAILING TEST.
KEEPING TESTS CLEAN
• “QUICK AND DIRTY”
• TEST CODE DID NOT NEED TO BE WELL DESIGNED AND
THOUGHTFULLY PARTITIONED
• COVERED THE PRODUCTION CODE, IT’S GOOD ENOUGH.
KEEPING TESTS CLEAN
• DIRTY TEST WILL BE MAKE YOU SLOWER
• WHEN THE COST OF MAINTAIN A TEST IS MAJOR OF
WRITING A CODE IT IS NOT SUSTAINABLE
• A TEST DESCRIBE A BEHAVIOR IF YOUR TEST IS NOT
UNDERSTANDABLE THE BEHAVIOR IS NOT
UNDERSTANDABLE
SIMPLE
WHAT MAKES ALL
CODE READABLE ?
• CLARITY
• SIMPLICITY
• AND DENSITY OF EXPRESSION
In a test you want to say a lot with as few
expressions as possible.
ONE ASSERT PER TEST • EVERY TEST FUNCTION IN A TEST SHOULD HAVE ONE AND
ONLY ONE ASSERT STATEMENT
• A BETTER RULE IS THAT WE WANT TO TEST A SINGLE
CONCEPT IN EACH TEST FUNCTION.
SINGLE CONCEPT PER TEST
KEEP IN MIND F.I.R.S.T.
• FAST TESTS TEST SHOULD RUN QUICKLY. WHEN TESTS RUN SLOWLY, YOU CAN’T RUN THEM
FREQUENTLY. IF YOU DON’T RUN THEM FREQUENTLY, YOU WON’T FIND PROBLEMS EARLY
ENOUGH TO FIX THEM EASILY.
• INDEPENDENT TESTS SHOULD NOT DEPEND ON EACH OTHER
• REPEATABLE TESTS SHOULD BE REPEATABLE IN ANY ENVIRONMENT. YOU SHOULD BE ABLE
TO RUN THE TESTS IN PRODUCTION, QA OR YOUR LAPTOP.
• SELF-VALIDATING TESTS SHOULD HAVE A BOOLEAN OUTPUT. EITHER THEY PASS OR FAIL.
• TIMELY UNIT TESTS SHOULD BE WRITTEN JUST BEFORE THE PRODUCTION CODE THAT
MAKES THEM PASS. IF YOU WRITE TESTS AFTER THE PRODUCTION CODE, THEN YOU MAY
FIND THE PRODUCTION CODE TO BE HARD TO TEST.
I
R
S
F
T
Chapter 9 TDD clean code book Robert C.Martin

Contenu connexe

Dernier

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Dernier (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Chapter 9 TDD clean code book Robert C.Martin

  • 1.
  • 2. THE THREE 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 IS FAILING. • THIRD LAW YOU MAY NOT WRITE MORE PRODUCTION CODE THAN IS SUFFICIENT TO PASS THE CURRENTLY FAILING TEST.
  • 3. KEEPING TESTS CLEAN • “QUICK AND DIRTY” • TEST CODE DID NOT NEED TO BE WELL DESIGNED AND THOUGHTFULLY PARTITIONED • COVERED THE PRODUCTION CODE, IT’S GOOD ENOUGH.
  • 4. KEEPING TESTS CLEAN • DIRTY TEST WILL BE MAKE YOU SLOWER • WHEN THE COST OF MAINTAIN A TEST IS MAJOR OF WRITING A CODE IT IS NOT SUSTAINABLE • A TEST DESCRIBE A BEHAVIOR IF YOUR TEST IS NOT UNDERSTANDABLE THE BEHAVIOR IS NOT UNDERSTANDABLE
  • 5.
  • 6.
  • 7.
  • 9.
  • 10. WHAT MAKES ALL CODE READABLE ? • CLARITY • SIMPLICITY • AND DENSITY OF EXPRESSION In a test you want to say a lot with as few expressions as possible.
  • 11. ONE ASSERT PER TEST • EVERY TEST FUNCTION IN A TEST SHOULD HAVE ONE AND ONLY ONE ASSERT STATEMENT • A BETTER RULE IS THAT WE WANT TO TEST A SINGLE CONCEPT IN EACH TEST FUNCTION. SINGLE CONCEPT PER TEST
  • 12. KEEP IN MIND F.I.R.S.T. • FAST TESTS TEST SHOULD RUN QUICKLY. WHEN TESTS RUN SLOWLY, YOU CAN’T RUN THEM FREQUENTLY. IF YOU DON’T RUN THEM FREQUENTLY, YOU WON’T FIND PROBLEMS EARLY ENOUGH TO FIX THEM EASILY. • INDEPENDENT TESTS SHOULD NOT DEPEND ON EACH OTHER • REPEATABLE TESTS SHOULD BE REPEATABLE IN ANY ENVIRONMENT. YOU SHOULD BE ABLE TO RUN THE TESTS IN PRODUCTION, QA OR YOUR LAPTOP. • SELF-VALIDATING TESTS SHOULD HAVE A BOOLEAN OUTPUT. EITHER THEY PASS OR FAIL. • TIMELY UNIT TESTS SHOULD BE WRITTEN JUST BEFORE THE PRODUCTION CODE THAT MAKES THEM PASS. IF YOU WRITE TESTS AFTER THE PRODUCTION CODE, THEN YOU MAY FIND THE PRODUCTION CODE TO BE HARD TO TEST. I R S F T

Notes de l'éditeur

  1. The tests and the production code are written together, with the tests just a few seconds ahead of the production code.
  2. Test code is just as important as production code