Brief introduction to TDD

897 views

Published on

A brief presentation about what's TDD and what are the advantages.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
897
On SlideShare
0
From Embeds
0
Number of Embeds
434
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Brief introduction to TDD

  1. 1. Test Driven Developmenta brief introductionEmanuele Blancoemanuele.blanco@gmail.comhttp://blog.manub.net@manub
  2. 2. Notable Software FailuresAriane 5In 1996, first launch endedin self-destruction after 37seconds.Cost: ~$500 million
  3. 3. Notable Software FailuresAriane 5An overflow happenedduring the conversion froma 64-bit float to a 16-bitsigned integer, causing aprocessor trap.
  4. 4. Improving Software QualitySoftware Quality: "capability of a softwareproduct to conform to requirements" (ISO/IEC9001)How can we write software that betterconforms to requirements?
  5. 5. Test Driven Development
  6. 6. Test Driven DevelopmentRequirements are written beforeimplementation, using tests (unit/integration)Production code is only written to make thetests pass - in other words, only to satisfyrequirements!If theres not a requirement (hence a test)...You Aint Gonna Need It!
  7. 7. TDD CycleRED: write a test for arequirement that has notbeen implemented yet...GREEN: write the minimumcode to make the testpass...REFACTOR: do not repeatyourself, extract methods,remove code smells... tidyup the camp!
  8. 8. TDD Rules● No production code can be written withouta test● The test should ALWAYS fail before startingto write code● Drive objects and methods creation fromthe test, using your IDE● Do the minimum required to have yourcurrent test pass without breaking theprevious● Never skip refactor phase!!!
  9. 9. TDD Best Practices● Write your asserts first● Outside-In approach● Never refactor on a failing test● Write Class Responsibility Collaborationcards in advance● Drive collaborators development by testinginteractions with the current class
  10. 10. TDD Benefits● Testable code● High coverage (but coverage is not agoal...)● Nothing more than what needed isdelivered (no surprises)● Clean code (provided refactoring is neverskipped)● Productivity improves with time -developers have trust in changing the code(new features and maintenance)
  11. 11. TDD Myths (aka Disclaimer)● TDD immediately gives you all the benefits○ The learning curve is steep, but in the mid-termpays off with higher productivity and less defects.○ Should be gradually introduced and practiced● TDD gives you 100% bug-free code○ Drastically reduces the bug rate but...Program testing could show the presence of bugs,never their absence!E. Dijkstra
  12. 12. Questions?

×