SlideShare une entreprise Scribd logo
1  sur  20
Test Driven
Development
Test Driven
Development
 Technique to design and develop software.
 Practice part of the Extreme Programming methodology — XP
 Based on three fundamental pillars.
TheThree
Pillars
 Implement the exact
functionality of the software.
 Reduce the number of defects
on the software – good quality
software
 Produce modular and highly
reusable software.
When Doing
TDD
 It’s not about just writing tests.
 Translate use cases to examples.
 Enough to describe the functionality without ambiguity.
 Architecture will eventually emerge.
TheTDD
Algorithm
Red
GreenRefactor
TheTDD
Algorithm
Red
GreenRefactor
TDD InAction
With an example ;-)
The Problem Email validation mechanism
The Problem
Email validation mechanism
The Problem
Email validation mechanism
Neither empty nor null.
Has to contain an @ symbol
Has to belong to the .com, .net and .eduTDLs
Domain part can’t be 1 character long
All lowercase
Not contain numbers
Only _ . - symbols
Before we
begin
WritingTests
 Testing framework
 Part of the language
 Ruby
 Rust
 Go
 Python
 External tools and libraries
TestNG
MSTest
Neither empty nor null
Red
@Test
public void shouldReturnFalseIfEmailIsNull() {
String email = null;
EmailValidator validator = new EmailValidator();
boolean isValid = validator.isValid(email);
assertThat(isValid, equalTo(false));
}
Neither empty nor null
Green public boolean isValid(String email) {
return false;
}
Neither empty nor null
Red
@Test
public void shouldReturnTrueIfEmailLengthIsGreaterThanZero() {
String email = "some@email.com";
EmailValidator validator = new EmailValidator();
boolean isValid = validator.isValid(email);
assertThat(isValid, equalTo(true));
}
Neither empty nor null
Green
public boolean isValid(String email) {
if (email == null) {
return false;
}
return email.length() > 0;
}
Contains an @ symbol
Red
@Test
public void shouldReturnFalseIfEmailDoesntContainAtSymbol () {
String email = "someemail.com";
EmailValidator validator = new EmailValidator();
boolean isValid = validator.isValid(email);
assertThat(isValid, equalTo(false));
}
Neither empty nor null
Green
public boolean isValid(String email) {
if (email == null) {
return false;
}
if (!email.contains("@")) {
return false;
}
return email.length() > 0;
}
Refactor
private EmailValidator validator;
@Before
public void setUp () {
validator = new EmailValidator();
}
In the end…
 Components will behave exactly as we want.
 Tests will be the documentation of our system.
 Tests will break if changes compromise the system.
Thank you!
Carlos Andrés Oquendo
coquendo@thoughtworks.com
@andres19_05

Contenu connexe

Tendances

Design concerns for concrete syntax
Design concerns for concrete syntaxDesign concerns for concrete syntax
Design concerns for concrete syntaxMikhail Barash
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
5 black box and grey box testing
5   black box and grey box testing5   black box and grey box testing
5 black box and grey box testingYisal Khan
 
White Box Testing
White Box TestingWhite Box Testing
White Box TestingAlisha Roy
 
Black Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath MBlack Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath MForziatech
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Myeongseok Baek
 
Considered the brain of the computer gpu cpu/tutorialoutlet
Considered the brain of the computer gpu cpu/tutorialoutletConsidered the brain of the computer gpu cpu/tutorialoutlet
Considered the brain of the computer gpu cpu/tutorialoutletDanielsonz
 
Test-drive development and Umple
Test-drive development and UmpleTest-drive development and Umple
Test-drive development and Umpletylerjdmcconnell
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented TestingDamian T. Gordon
 
Ch07 Programming for Security Professionals
Ch07 Programming for Security ProfessionalsCh07 Programming for Security Professionals
Ch07 Programming for Security Professionalsphanleson
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practiceMikhail Barash
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard partsShaun Abram
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated TestingLee Englestone
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 

Tendances (20)

Design concerns for concrete syntax
Design concerns for concrete syntaxDesign concerns for concrete syntax
Design concerns for concrete syntax
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
5 black box and grey box testing
5   black box and grey box testing5   black box and grey box testing
5 black box and grey box testing
 
White box testing
White box testingWhite box testing
White box testing
 
White Box Testing
White Box TestingWhite Box Testing
White Box Testing
 
Black Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath MBlack Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath M
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
DISE - Programming Concepts
DISE - Programming ConceptsDISE - Programming Concepts
DISE - Programming Concepts
 
St 1.3
St 1.3St 1.3
St 1.3
 
Considered the brain of the computer gpu cpu/tutorialoutlet
Considered the brain of the computer gpu cpu/tutorialoutletConsidered the brain of the computer gpu cpu/tutorialoutlet
Considered the brain of the computer gpu cpu/tutorialoutlet
 
Test-drive development and Umple
Test-drive development and UmpleTest-drive development and Umple
Test-drive development and Umple
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
 
Ch07 Programming for Security Professionals
Ch07 Programming for Security ProfessionalsCh07 Programming for Security Professionals
Ch07 Programming for Security Professionals
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practice
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
DSLs: what, why, how
DSLs: what, why, howDSLs: what, why, how
DSLs: what, why, how
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 

En vedette

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
 
The Power of BDD
The Power of BDDThe Power of BDD
The Power of BDDNancy Cai
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Introduction to Test Driven Development [TDD]
Introduction to Test Driven Development [TDD]Introduction to Test Driven Development [TDD]
Introduction to Test Driven Development [TDD]Ashish K Agarwal
 
Test-Driven Development (TDD) - MSP Coding Day
Test-Driven Development (TDD) - MSP Coding DayTest-Driven Development (TDD) - MSP Coding Day
Test-Driven Development (TDD) - MSP Coding DayRenato Groff
 
How to bdd with concordion
How to bdd with concordionHow to bdd with concordion
How to bdd with concordionAMikitas
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentJoshua Partogi
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentjakubkoci
 

En vedette (10)

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
 
Selenium and Continuous Intergration
Selenium and Continuous IntergrationSelenium and Continuous Intergration
Selenium and Continuous Intergration
 
Bdd
BddBdd
Bdd
 
The Power of BDD
The Power of BDDThe Power of BDD
The Power of BDD
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Introduction to Test Driven Development [TDD]
Introduction to Test Driven Development [TDD]Introduction to Test Driven Development [TDD]
Introduction to Test Driven Development [TDD]
 
Test-Driven Development (TDD) - MSP Coding Day
Test-Driven Development (TDD) - MSP Coding DayTest-Driven Development (TDD) - MSP Coding Day
Test-Driven Development (TDD) - MSP Coding Day
 
How to bdd with concordion
How to bdd with concordionHow to bdd with concordion
How to bdd with concordion
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Similaire à TDD Explained: The Red-Green-Refactor Process

TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Babul Mirdha
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysisPVS-Studio
 
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...ESEM 2014
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
Presentation Test Driven Development
Presentation Test Driven DevelopmentPresentation Test Driven Development
Presentation Test Driven DevelopmentRashmi Srivastava
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide vitalipe
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development IntroductionNguyen Hai
 

Similaire à TDD Explained: The Red-Green-Refactor Process (20)

Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Testing and symfony2
Testing and symfony2Testing and symfony2
Testing and symfony2
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd
TddTdd
Tdd
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
 
Tdd
TddTdd
Tdd
 
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Presentation Test Driven Development
Presentation Test Driven DevelopmentPresentation Test Driven Development
Presentation 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 - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 

Dernier

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

TDD Explained: The Red-Green-Refactor Process

  • 2. Test Driven Development  Technique to design and develop software.  Practice part of the Extreme Programming methodology — XP  Based on three fundamental pillars.
  • 3. TheThree Pillars  Implement the exact functionality of the software.  Reduce the number of defects on the software – good quality software  Produce modular and highly reusable software.
  • 4. When Doing TDD  It’s not about just writing tests.  Translate use cases to examples.  Enough to describe the functionality without ambiguity.  Architecture will eventually emerge.
  • 7. TDD InAction With an example ;-)
  • 8. The Problem Email validation mechanism
  • 10. The Problem Email validation mechanism Neither empty nor null. Has to contain an @ symbol Has to belong to the .com, .net and .eduTDLs Domain part can’t be 1 character long All lowercase Not contain numbers Only _ . - symbols
  • 11. Before we begin WritingTests  Testing framework  Part of the language  Ruby  Rust  Go  Python  External tools and libraries TestNG MSTest
  • 12. Neither empty nor null Red @Test public void shouldReturnFalseIfEmailIsNull() { String email = null; EmailValidator validator = new EmailValidator(); boolean isValid = validator.isValid(email); assertThat(isValid, equalTo(false)); }
  • 13. Neither empty nor null Green public boolean isValid(String email) { return false; }
  • 14. Neither empty nor null Red @Test public void shouldReturnTrueIfEmailLengthIsGreaterThanZero() { String email = "some@email.com"; EmailValidator validator = new EmailValidator(); boolean isValid = validator.isValid(email); assertThat(isValid, equalTo(true)); }
  • 15. Neither empty nor null Green public boolean isValid(String email) { if (email == null) { return false; } return email.length() > 0; }
  • 16. Contains an @ symbol Red @Test public void shouldReturnFalseIfEmailDoesntContainAtSymbol () { String email = "someemail.com"; EmailValidator validator = new EmailValidator(); boolean isValid = validator.isValid(email); assertThat(isValid, equalTo(false)); }
  • 17. Neither empty nor null Green public boolean isValid(String email) { if (email == null) { return false; } if (!email.contains("@")) { return false; } return email.length() > 0; }
  • 18. Refactor private EmailValidator validator; @Before public void setUp () { validator = new EmailValidator(); }
  • 19. In the end…  Components will behave exactly as we want.  Tests will be the documentation of our system.  Tests will break if changes compromise the system.
  • 20. Thank you! Carlos Andrés Oquendo coquendo@thoughtworks.com @andres19_05

Notes de l'éditeur

  1. Design: * We normally rush to start coding a solution without thinking much about the problem itself.
  2. Exact functionality: *
  3. Examples: Traditionally we will code based on use cases that describe the functionality with natural language. Most of the times there is ambiguity expressed on them because of our language. The idea is to generate as much examples as needed in order to remove all the ambiguity. Architecture: Will emerge at a higher level. Depends on the type of application we are implementing and the technologies we are using. Not that we should not think on architectural decisions or concerns, but we will postpone them until they are necessary. Normally we design applications having several layers, transfer objects, factories and so on, but we may not need them. Freedom to the developer. In some contexts, all has to be coded the same way.
  4. Red We’ll start writing a test for a certain example. Why? Compilation errors Test failures Green We’ll implement the minimum possible functionality to cover the test case. We’ll be tempted to write a bit more code. We should be strong. Refactor We’ll revisit our test and implementation code to see if we can improve something without changing the functionality. What can we do? Clean the code Extract variables, Reduce duplication We should try to improve something, at least a bit. Sometimes it won’t be obvious, but we should spend a bit of time trying to refactor.
  5. What does email validation mean for this specific context? The fact is that validating an email, although sounds universal, may be very specific depending on the business context.
  6. To write tests we need some technology support, which is presented as a Testing Framework. Some languages and frameworks include some kind of unit testing support, such as … But in any case there are several unit testing frameworks we can use to write tests for our code, even if the language does provide some testing support. Just to name a few Java .NET JavaScript
  7. We’d like to refactor, but the code is so tiny…
  8. We’d like to refactor, but the code is so tiny…
  9. We’d like to refactor, but the code is so tiny…
  10. We’d like to refactor, but the code is so tiny…