SlideShare a Scribd company logo
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

More Related Content

PPTX
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
PDF
TDD in the ABAP world - sitNL 2013 edition
PDF
Cyclomatic complexity
PDF
javabasics_ programming development chapter01
PPTX
The Psychology of C# Analysis
PPTX
UNIT testing
PPT
Black box testing
PDF
Improving the accuracy and reliability of data analysis code
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
TDD in the ABAP world - sitNL 2013 edition
Cyclomatic complexity
javabasics_ programming development chapter01
The Psychology of C# Analysis
UNIT testing
Black box testing
Improving the accuracy and reliability of data analysis code

What's hot (20)

PDF
Design concerns for concrete syntax
PPTX
Testing the untestable
PPTX
5 black box and grey box testing
PPTX
White box testing
PPTX
White Box Testing
PPTX
Black Box Testing Techniques by Sampath M
PDF
Ddc2011 효과적으로레거시코드다루기
PPSX
DISE - Programming Concepts
DOC
Considered the brain of the computer gpu cpu/tutorialoutlet
PDF
Test-drive development and Umple
PPTX
Python: Object-oriented Testing
PPT
Ch07 Programming for Security Professionals
PDF
TDD Workshop UTN 2012
PPTX
Software Design Principles and Best Practices - Satyajit Dey
PDF
Implementing DSLs in practice
PPTX
Unit testing - the hard parts
PPTX
Unit Tests And Automated Testing
PDF
DSLs: what, why, how
PDF
Fundamentals of programming)
Design concerns for concrete syntax
Testing the untestable
5 black box and grey box testing
White box testing
White Box Testing
Black Box Testing Techniques by Sampath M
Ddc2011 효과적으로레거시코드다루기
DISE - Programming Concepts
Considered the brain of the computer gpu cpu/tutorialoutlet
Test-drive development and Umple
Python: Object-oriented Testing
Ch07 Programming for Security Professionals
TDD Workshop UTN 2012
Software Design Principles and Best Practices - Satyajit Dey
Implementing DSLs in practice
Unit testing - the hard parts
Unit Tests And Automated Testing
DSLs: what, why, how
Fundamentals of programming)
Ad

Viewers also liked (10)

PDF
Introduction to TDD (Test Driven development) - Ahmed Shreef
PPTX
Selenium and Continuous Intergration
PDF
PPTX
The Power of BDD
PDF
Acceptance Test Driven Development
PPTX
Introduction to Test Driven Development [TDD]
PPTX
Test-Driven Development (TDD) - MSP Coding Day
PPTX
How to bdd with concordion
PPTX
Acceptance Test Driven Development
PDF
Test Driven Development
Introduction to TDD (Test Driven development) - Ahmed Shreef
Selenium and Continuous Intergration
The Power of BDD
Acceptance Test Driven Development
Introduction to Test Driven Development [TDD]
Test-Driven Development (TDD) - MSP Coding Day
How to bdd with concordion
Acceptance Test Driven Development
Test Driven Development
Ad

Similar to Test Driven Development (TDD) Basics (20)

PDF
Test Driven Development SpeedRun
PPT
PPTX
TDD - Seriously, try it! - Opensouthcode
PPTX
Test-Driven Development.pptx
PPTX
Test driven development v1.0
PDF
Test Driven Development Introduction
PDF
Test Driven Development Powered by LEGO
PDF
Research Activities: past, present, and future.
PDF
Test Driven Development by Denis Lutz
PPTX
Test Driven Development - a Practitioner’s Perspective
PPTX
TDD - Seriously, try it - Codemotion (May '24)
PPT
TDD (Test Driven Design)
PDF
Majcon at abap code_retreat_stjohann_2017_fast track tdd
PDF
A Study: The Analysis of Test Driven Development And Design Driven Test
PPTX
Test-Driven-Development.pptx
PPTX
TDD in Agile
PPTX
TDD - Seriously, try it! (updated '22)
PPTX
Cleaner Code Through Test-Driven Development
PPTX
Presentation Test Driven Development
Test Driven Development SpeedRun
TDD - Seriously, try it! - Opensouthcode
Test-Driven Development.pptx
Test driven development v1.0
Test Driven Development Introduction
Test Driven Development Powered by LEGO
Research Activities: past, present, and future.
Test Driven Development by Denis Lutz
Test Driven Development - a Practitioner’s Perspective
TDD - Seriously, try it - Codemotion (May '24)
TDD (Test Driven Design)
Majcon at abap code_retreat_stjohann_2017_fast track tdd
A Study: The Analysis of Test Driven Development And Design Driven Test
Test-Driven-Development.pptx
TDD in Agile
TDD - Seriously, try it! (updated '22)
Cleaner Code Through Test-Driven Development
Presentation Test Driven Development

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Empathic Computing: Creating Shared Understanding
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPT
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Empathic Computing: Creating Shared Understanding
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Assigned Numbers - 2025 - Bluetooth® Document
Teaching material agriculture food technology

Test Driven Development (TDD) Basics

  • 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

Editor's Notes

  • #3: Design: * We normally rush to start coding a solution without thinking much about the problem itself.
  • #4: Exact functionality: *
  • #5: 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.
  • #6: 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.
  • #10: 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.
  • #12: 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
  • #14: We’d like to refactor, but the code is so tiny…
  • #16: We’d like to refactor, but the code is so tiny…
  • #18: We’d like to refactor, but the code is so tiny…
  • #19: We’d like to refactor, but the code is so tiny…