Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Test-driven Development

Introduction to Test-driven Development

Davide Fucci

June 19, 2014
Tweet

More Decks by Davide Fucci

Other Decks in Programming

Transcript

  1. What is TDD? § It is an iterative development technique § Focused

    on design rather than validation § Also referred as: Test first development
  2. TDD effects § Improve and speed up software development § Have flexible

    and extensible code § Reduce bugs § Improve documentation
  3. TDD mantra § Write test before implementation § Refactor, refactor, refactor § Relies

    on unit testing and unit testing frameworks § ”Unit tests run fast, if they do not run fast they are not unit tests”
  4. TDD: step 1 § Think in terms of baby steps § Focus

    on the behaviour you wish your code will have THINK
  5. TDD: step 2 § Write a test, watch it fail § Focus

    on the behaviour your class and method will have § A.K.A. name your API properly THINK FAIL
  6. TDD: step 3 § Write the code, make it pass § Write

    the minimal amount of code that makes the test pass THINK FAIL PASS
  7. TDD: step 4 § Simplify and improve the design § Do NOT

    modify the behaviour! THINK FAIL PASS REFACTOR
  8. Limitations § Steep learning curve § It requires discipline to conform to

    the process § Hard to apply to GUI development § Hard to apply to legacy code
  9. Exercise For this exercise you will implement as simplified version

    of a tennis game using Test-driven development: §  A game is won by the first player to have won at least four points in total and at least two points more than the opponent. §  The running score of each game is described in a manner peculiar to tennis: scores from zero to three points are described as "love", "fifteen", "thirty", and "forty" respectively. §  If at least three points have been scored by each player, and the scores are equal, the score is "deuce". §  If at least three points have been scored by each side and a player has one more point than his opponent, the score of the game is "advantage" for the player in the lead.