SlideShare a Scribd company logo
Introducción práctica a
Test-Driven Development
Software Craftsmanship Alicante
Who am I?
• Rubén Antón A.K.A
@rubocoptero
• Crafting code for Flywire
• h4ckademy alumni
What’s TDD?
TDD is not testing!
Two simple rules
• Don’t write a line of new code unless you first have
a failing automated test.
• Eliminate duplication.
What is TDD?
• XP practice that combines Test-First and
Refactoring
• Tests as a design tool
• KISS
• Baby steps
Mantra
Steps
1. ROJO: write a little test that doesn’t work, perhaps
doesn’t even compile at first
2. GREEN: make the test work quickly, committing
whatever sins necessary in the process
3. REFACTOR: eliminate all the duplication created
in just getting the test to work.
Why use TDD?
Benefits
• Manually verification is time consuming
• Break down our work into manageable chunks
• Source of documentation
• Avoid over-engineering
• Safety net
• Encourages Loosely Coupled Design
–Chris Jordan
“Software is inherently complex, and being able
to make things easier for ourselves as
developers is a crucial part of our role to deliver
high quality software.”
Techniques
Fake it (’til you make it)
1. Return a constant to make it pass
2. Gradually replace constants with variables until
you have the real code
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
}
private int Sum(int x, int y)
{
return 4
}
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
}
private int Sum(int x, int y)
{
return 3 + 1;
}
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
Assert.Equals(5, Sum(3, 2));
}
private int Sum(int x, int y)
{
return x + y;
}
Triangulation
• Use two or three test cases before to generalize.
• Only use it when completely unsure of how to refactor.
• What axes of variability are you trying to support in
your design?
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
}
private int Sum(int x, int y)
{
return 4
}
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
Assert.Equals(5, Sum(3, 2));
}
private int Sum(int x, int y)
{
return x + y;
}
[TestMethod]
public void TestSum()
{
Assert.Equals(4, Sum(3, 1));
Assert.Equals(5, Sum(3, 2));
}
private int Sum(int x, int y)
{
return x + y;
}
Obvious Implementation
• Fake it and Triangulation use baby steps.
• If you think it’s obvious, type in the real
implementation.
• It’s a "second gear".
• If you get an unexpected red bar, back up.
–Kent Beck
“Remember, TDD is not about taking teensy tiny
steps, it’s about being able to take teensy tiny
steps. Would I code day-to-day with steps this
small? No. But when things get the least bit
weird, I’m glad I can.”
Let’s practice…
just a few last things before to start.
Rules
• 30 seconds to go from RED to GREEN
• Don’t lose the GREEN in the refactoring phase.
• No debug
Good tests
• Imagine the perfect interface for our operation
• Fast
• Independents
• Arrange - Act - Assert
// Arrange
MyProductionClass myProductionClass = new MyProductionClass();
// Act
bool result = myProductionClass.GetBooleanResult();
// Assert
Assert.IsTrue(result);
Before you start
• The focus is to practice writing the best code we
can possibly write and challenge ourselves. It is
important to mention that the goal is not to finish
the exercise as soon as posible, but to learn during
the process via the discussion with our partner.
• Do one task at a time. The trick is to learn to work
incrementally.
• Make sure you only test for correct inputs. there is
no need to test for invalid inputs for this kata
FizzBuzz
Return “fizz”, “buzz” or “fizzbuzz”.
For a given natural number greater
zero return:
• “fizz” if it is dividable by 3
• “buzz” if it is dividable by 5
• “fizzbuzz” if it is dividable by 3 and
5.
Input Result
1 1
2 2
3 fizz
6 fizz
5 buzz
10 buzz
15 fizzbuzz
30 fizzbuzz
FizzBuzz continuation
• A number is "fizz" if it is divisible by 3 or if it has a 3
in it.
• A number is "buzz" if it is divisible by 5 or if it has a
5 in it.
Retrospective time
• What difficulties do we found?
• What we have done?
• What we have learnt?
TDD economy
• Either you will have to be able to write twice as
many lines per day as before, or write half as many
lines for the same functionality.
• You’ll have to measure and see what effect TDD
has on your own practice.
• Be sure to factor debugging, integrating, and
explaining time into your metrics, though.
More than TDD
• Extreme Programming
practices
• SOLID
• Clean Code
• 4 rules of simple design
How can I learn it?
• Practice, practice and practice!
• Read good books
• TDD by example - Kent Beck
• Clean Code - Uncle Bob
• Refactoring - Martin Fowler
• Test Driven - Lasse Koskela
• …
Thank you all!

More Related Content

PDF
Introducción a TDD
PPT
Matlab tips and tricks
PPTX
Test with Spock like the first officer
ZIP
Test Driven Development
PDF
Baby Steps TDD Approaches
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
PDF
Test-Driven Development
PDF
iOS Test-Driven Development
Introducción a TDD
Matlab tips and tricks
Test with Spock like the first officer
Test Driven Development
Baby Steps TDD Approaches
TDD reloaded - JUGTAA 24 Ottobre 2012
Test-Driven Development
iOS Test-Driven Development

Similar to Introducción práctica a TDD (20)

PPTX
TDD: seriously, try it! 
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PPT
CPP10 - Debugging
PDF
Bdd and-testing
PDF
Behaviour Driven Development and Thinking About Testing
 
PDF
Day1 - TDD (Lecture SS 2015)
PPTX
2016 10-04: tdd++: tdd made easier
PDF
TDD Flow: The Mantra in Action
PPTX
Pair programming and introduction to TDD
PPTX
Test Driven Development on Android (Kotlin Kenya)
PDF
Test Driven Development
PPTX
Intro to TDD
PDF
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
PDF
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
PDF
Getting started with Test Driven Development
PPTX
Getting started with Test Driven Development - Ferdous Mahmud Shaon
PPTX
TDD a piccoli passi
PPT
Software testing (2) trainingin-mumbai...
PPT
Software testing (2) trainingin-mumbai
PDF
Basic TDD moves
TDD: seriously, try it! 
TDD and Simple Design Workshop - Session 1 - March 2019
CPP10 - Debugging
Bdd and-testing
Behaviour Driven Development and Thinking About Testing
 
Day1 - TDD (Lecture SS 2015)
2016 10-04: tdd++: tdd made easier
TDD Flow: The Mantra in Action
Pair programming and introduction to TDD
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development
Intro to TDD
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
Getting started with Test Driven Development
Getting started with Test Driven Development - Ferdous Mahmud Shaon
TDD a piccoli passi
Software testing (2) trainingin-mumbai...
Software testing (2) trainingin-mumbai
Basic TDD moves
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
history of c programming in notes for students .pptx
PDF
medical staffing services at VALiNTRY
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Essential Infomation Tech presentation.pptx
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
history of c programming in notes for students .pptx
medical staffing services at VALiNTRY
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ai tools demonstartion for schools and inter college
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Online Work Permit System for Fast Permit Processing
Softaken Excel to vCard Converter Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Materi-Enum-and-Record-Data-Type (1).pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Materi_Pemrograman_Komputer-Looping.pptx
ManageIQ - Sprint 268 Review - Slide Deck
Essential Infomation Tech presentation.pptx
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Ad

Introducción práctica a TDD

  • 1. Introducción práctica a Test-Driven Development Software Craftsmanship Alicante
  • 2. Who am I? • Rubén Antón A.K.A @rubocoptero • Crafting code for Flywire • h4ckademy alumni
  • 4. TDD is not testing!
  • 5. Two simple rules • Don’t write a line of new code unless you first have a failing automated test. • Eliminate duplication.
  • 6. What is TDD? • XP practice that combines Test-First and Refactoring • Tests as a design tool • KISS • Baby steps
  • 8. Steps 1. ROJO: write a little test that doesn’t work, perhaps doesn’t even compile at first 2. GREEN: make the test work quickly, committing whatever sins necessary in the process 3. REFACTOR: eliminate all the duplication created in just getting the test to work.
  • 10. Benefits • Manually verification is time consuming • Break down our work into manageable chunks • Source of documentation • Avoid over-engineering • Safety net • Encourages Loosely Coupled Design
  • 11. –Chris Jordan “Software is inherently complex, and being able to make things easier for ourselves as developers is a crucial part of our role to deliver high quality software.”
  • 13. Fake it (’til you make it) 1. Return a constant to make it pass 2. Gradually replace constants with variables until you have the real code [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); } private int Sum(int x, int y) { return 4 } [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); } private int Sum(int x, int y) { return 3 + 1; } [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); Assert.Equals(5, Sum(3, 2)); } private int Sum(int x, int y) { return x + y; }
  • 14. Triangulation • Use two or three test cases before to generalize. • Only use it when completely unsure of how to refactor. • What axes of variability are you trying to support in your design? [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); } private int Sum(int x, int y) { return 4 } [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); Assert.Equals(5, Sum(3, 2)); } private int Sum(int x, int y) { return x + y; } [TestMethod] public void TestSum() { Assert.Equals(4, Sum(3, 1)); Assert.Equals(5, Sum(3, 2)); } private int Sum(int x, int y) { return x + y; }
  • 15. Obvious Implementation • Fake it and Triangulation use baby steps. • If you think it’s obvious, type in the real implementation. • It’s a "second gear". • If you get an unexpected red bar, back up.
  • 16. –Kent Beck “Remember, TDD is not about taking teensy tiny steps, it’s about being able to take teensy tiny steps. Would I code day-to-day with steps this small? No. But when things get the least bit weird, I’m glad I can.”
  • 17. Let’s practice… just a few last things before to start.
  • 18. Rules • 30 seconds to go from RED to GREEN • Don’t lose the GREEN in the refactoring phase. • No debug
  • 19. Good tests • Imagine the perfect interface for our operation • Fast • Independents • Arrange - Act - Assert // Arrange MyProductionClass myProductionClass = new MyProductionClass(); // Act bool result = myProductionClass.GetBooleanResult(); // Assert Assert.IsTrue(result);
  • 20. Before you start • The focus is to practice writing the best code we can possibly write and challenge ourselves. It is important to mention that the goal is not to finish the exercise as soon as posible, but to learn during the process via the discussion with our partner. • Do one task at a time. The trick is to learn to work incrementally. • Make sure you only test for correct inputs. there is no need to test for invalid inputs for this kata
  • 21. FizzBuzz Return “fizz”, “buzz” or “fizzbuzz”. For a given natural number greater zero return: • “fizz” if it is dividable by 3 • “buzz” if it is dividable by 5 • “fizzbuzz” if it is dividable by 3 and 5. Input Result 1 1 2 2 3 fizz 6 fizz 5 buzz 10 buzz 15 fizzbuzz 30 fizzbuzz
  • 22. FizzBuzz continuation • A number is "fizz" if it is divisible by 3 or if it has a 3 in it. • A number is "buzz" if it is divisible by 5 or if it has a 5 in it.
  • 23. Retrospective time • What difficulties do we found? • What we have done? • What we have learnt?
  • 24. TDD economy • Either you will have to be able to write twice as many lines per day as before, or write half as many lines for the same functionality. • You’ll have to measure and see what effect TDD has on your own practice. • Be sure to factor debugging, integrating, and explaining time into your metrics, though.
  • 25. More than TDD • Extreme Programming practices • SOLID • Clean Code • 4 rules of simple design
  • 26. How can I learn it? • Practice, practice and practice! • Read good books • TDD by example - Kent Beck • Clean Code - Uncle Bob • Refactoring - Martin Fowler • Test Driven - Lasse Koskela • …