TDD
Test Driven Development
The best thing that has happened to software design
Arek Torczuk, ThoughtWorks
Definition
“Test-Driven Development (TDD) is a software development process that relies on the repetition of a very
short development cycle: requirements are turned into very specific test cases, then the software is
improved so that the tests pass.”
Wikipedia
History
● 1950’s: “Test First” approach discovered.
● 1998: Kent Beck (XP) rediscovers this principle.
● 2003: Beck coined the term TDD.
Software Craftsmanship Principles
● Not only working software, but also well-crafted software
● Not only responding to change,but also steadily adding value
● Not only individuals and interactions, but also a community of professionals
● Not only customer collaboration, but also productive partnerships
TDD helps support these principles.
Common Software Development Problems
● Difficulty in testing code
● Over-engineered solutions
● “While I’m working on this” syndrome
● Fear of refactoring
Advantages of TDD
● Maintaining a high standard of quality
● Building an optimal code coverage
● Emergent Design
● Clean Code, Testable Code
● Allows for refactoring
● Ultimately, go faster
The three laws of the TDD cycle
1. Write a failing test
2. Write just enough code to pass the test
3. Refactor
Workshop - Lego
Lego Workshop - Setup
● Goal: Use TDD to build a car
● Challenge: Implementation changes should not affect tests
● You are given:
● A bag of Legos
● One highlighter
● Two types of grid paper
● A list of requirements
Lego Workshop - Rules
● Draw your test first:
● Use the plate as a reference point.
● Add as few legos as possible to make your test pass.
● Make sure your test suite still passes before implementing the subsequent
requirement.
Requirement 1: Car must have a plate for the floor.
Large car (6 x 8) Small car (4 x 8)
Requirement 2: Body of the car must be one block high.
Large car (6 x 8) Small car (4 x 8)
Requirement 3: Car must have a steering wheel.
Large car (6 x 8) Small car (4 x 8)
Requirement 4: Car must accommodate one driver.
Large car (6 x 8) Small car (4 x 8)
Requirement 5: Car must have a windshield.
Large car (6 x 8) Small car (4 x 8)
Requirement 6: Car must have four wheels.
Large car (6 x 8) Small car (4 x 8)
Congratulations!!!
The customer is very happy with your
car!
You have obtained more budget to
continue building your car!!!
Refactoring
● You have to change your existing design to satisfy new customer requirements.
● Do not forget to update your tests if needed and make sure that they always pass!
Off to work we go!
New Requirements
● Requirement 7: Car must have a yellow decorative line on each side of the car.
● Requirement 8: Car must have a rear spoiler.
Final Product!
Exercise Review
● TDD eases refactoring:
○ Creates an optimal test coverage.
○ Increases confidence in the code.
○ Removes fear of change/ regression.
● Aim for one validation per test.
● Test the state after execution, not the implementation.
???
References
Kent Beck explains that TDD has existed for longer than we think.
https://arialdomartini.wordpress.com/2012/07/20/you-wont-believe-how-old-tdd-is/
Kent Beck - Test Driven Development
https://www.amazon.ca/Test-Driven-Development-Kent-Beck/dp/0321146530
TDD: the best thing that has happened to software design
https://www.thoughtworks.com/pt/insights/blog/test-driven-development-best-thing-has-happened-software-design
Why TDD
https://builttoadapt.io/why-tdd-489fdcdda05e
Why TDD will change your developer life?
https://medium.com/@raphaelyoshiga/why-tdd-will-change-your-developer-life-b0bf234e15ac
Available Training Classes
● DevOps
● Clean Architecture
● TDD
● ATDD
● BDD
● Testable Code
● Clean Code
● SOLID Principles
● Automated Testing
Please take a minute, we need your feedback.
Find us on Guideview’s mobile app!

Test Driven Development Powered by LEGO

  • 1.
    TDD Test Driven Development Thebest thing that has happened to software design Arek Torczuk, ThoughtWorks
  • 2.
    Definition “Test-Driven Development (TDD)is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved so that the tests pass.” Wikipedia
  • 3.
    History ● 1950’s: “TestFirst” approach discovered. ● 1998: Kent Beck (XP) rediscovers this principle. ● 2003: Beck coined the term TDD.
  • 4.
    Software Craftsmanship Principles ●Not only working software, but also well-crafted software ● Not only responding to change,but also steadily adding value ● Not only individuals and interactions, but also a community of professionals ● Not only customer collaboration, but also productive partnerships TDD helps support these principles.
  • 5.
    Common Software DevelopmentProblems ● Difficulty in testing code ● Over-engineered solutions ● “While I’m working on this” syndrome ● Fear of refactoring
  • 6.
    Advantages of TDD ●Maintaining a high standard of quality ● Building an optimal code coverage ● Emergent Design ● Clean Code, Testable Code ● Allows for refactoring ● Ultimately, go faster
  • 7.
    The three lawsof the TDD cycle 1. Write a failing test 2. Write just enough code to pass the test 3. Refactor
  • 8.
  • 9.
    Lego Workshop -Setup ● Goal: Use TDD to build a car ● Challenge: Implementation changes should not affect tests ● You are given: ● A bag of Legos ● One highlighter ● Two types of grid paper ● A list of requirements
  • 10.
    Lego Workshop -Rules ● Draw your test first: ● Use the plate as a reference point. ● Add as few legos as possible to make your test pass. ● Make sure your test suite still passes before implementing the subsequent requirement.
  • 11.
    Requirement 1: Carmust have a plate for the floor. Large car (6 x 8) Small car (4 x 8)
  • 12.
    Requirement 2: Bodyof the car must be one block high. Large car (6 x 8) Small car (4 x 8)
  • 13.
    Requirement 3: Carmust have a steering wheel. Large car (6 x 8) Small car (4 x 8)
  • 14.
    Requirement 4: Carmust accommodate one driver. Large car (6 x 8) Small car (4 x 8)
  • 15.
    Requirement 5: Carmust have a windshield. Large car (6 x 8) Small car (4 x 8)
  • 16.
    Requirement 6: Carmust have four wheels. Large car (6 x 8) Small car (4 x 8)
  • 17.
    Congratulations!!! The customer isvery happy with your car! You have obtained more budget to continue building your car!!!
  • 18.
    Refactoring ● You haveto change your existing design to satisfy new customer requirements. ● Do not forget to update your tests if needed and make sure that they always pass!
  • 19.
  • 20.
    New Requirements ● Requirement7: Car must have a yellow decorative line on each side of the car. ● Requirement 8: Car must have a rear spoiler.
  • 21.
  • 22.
    Exercise Review ● TDDeases refactoring: ○ Creates an optimal test coverage. ○ Increases confidence in the code. ○ Removes fear of change/ regression. ● Aim for one validation per test. ● Test the state after execution, not the implementation.
  • 23.
  • 24.
    References Kent Beck explainsthat TDD has existed for longer than we think. https://arialdomartini.wordpress.com/2012/07/20/you-wont-believe-how-old-tdd-is/ Kent Beck - Test Driven Development https://www.amazon.ca/Test-Driven-Development-Kent-Beck/dp/0321146530 TDD: the best thing that has happened to software design https://www.thoughtworks.com/pt/insights/blog/test-driven-development-best-thing-has-happened-software-design Why TDD https://builttoadapt.io/why-tdd-489fdcdda05e Why TDD will change your developer life? https://medium.com/@raphaelyoshiga/why-tdd-will-change-your-developer-life-b0bf234e15ac
  • 25.
    Available Training Classes ●DevOps ● Clean Architecture ● TDD ● ATDD ● BDD ● Testable Code ● Clean Code ● SOLID Principles ● Automated Testing
  • 26.
    Please take aminute, we need your feedback. Find us on Guideview’s mobile app!