SlideServe
Menu
Préférences
© SlideServe · v2026

PS4: Test Driven Development

zonta avatar
7 diapositives · 272 Views · Jul 17, 2014

PS4: Test Driven Development. Based on Test Driven Development by Example By Kent Beck . TDD Development Cycle. Start. Red – Write a little test that doesn’t work, and perhaps doesn’t even compile at first.

PS4: Test Driven Development - slide 1
01 / 7PS4: Test Driven Development
1 / 17

Télécharger la présentation

PS4: Test Driven Development
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. PS4: Test Driven Development Based on Test Driven Development by Example By Kent Beck 

  2. TDD Development Cycle Start Red– Write a little test that doesn’t work, and perhaps doesn’t even compile at first. Green – Make the test work quickly, committing whatever sins necessary in the process. Refactor – Eliminate all of the duplication created in merely getting the test to work. Software Engineering Spring 2011

  3. Make Test Work • The three approaches to making a test work cleanly are: • Fake it • It’s good for your morale to see your tests succeed. • Triangulation • It’s useful when you are not definitely sure what the correct abstraction is. • Obvious implementation • You should only apply the obvious implementation directly only if you are sure it will work. Software Engineering Spring 2011

  4. Fake It ('Til You Make It) What to do : • First implementation once you have a broken test return a constant. • Once you have the test running, gradually transform the constant into an expression using variables. When to use: • Usually when you cannot tell how to implement certain functionality, • or your previous steps were too large and you cannot figure out what went wrong. Why to use: • Something that works is better than something that doesn’t work! • Psychological— Having a green bar feels good (as opposed to having a red bar). • When the bar is green, you know where you stand. • You can refactor from there with confidence. • Scope control— Programmers are good at imagining all sorts of future problems. • Focus - Starting with one concrete example and generalizing from there prevents you from prematurely confusing yourself with extraneous concerns. • Focusing on the next test case is easier, knowing that the previous test is guaranteed to work. Does Fake It violate the rule that says you don't write any code that isn't needed? • Not really - because in the refactoring step you are eliminating duplication of data between the test case and the code. Software Engineering Spring 2011

  5. Triangulate What to do : • You set different cases in which the test should work and find the “generic” form of it later. When to use: • When you unsure about the correct abstraction and have two or more examples. Why to use: • By testing several (independent) points, we ensure that the implementation actually does not only satisfy the test cases. But • It takes extra work to write the second test, which does not necessarily add any additional information • After writing the new test, we may remain concerned that the implementation still only works correctly for a subset of the intended values. • Equivalence partitioning of input values can help to produce confidence that all equivalence classes are tested through at least one member • for example, negative numbers, zero, positive numbers, and Integer.MAX_VALUE Software Engineering Spring 2011

  6. Obvious Implementation What to do : • Just implement the simple operations. When to use: • When you are sure you know how to implement an operation. Why to use: • Fake It and Triangulation are teensy-weensy tiny steps. • If you know what to type, and you can do it quickly, then do it. BUT • By using only Obvious Implementation, you are demanding perfection of yourself. • Psychologically, this can be a devastating move. • What if what you write isn't really the simplest change that could get the test to pass? • What if your partner shows you an even simpler one? • You're a failure! Your world crumbles around you! You die. You freeze up. Software Engineering Spring 2011

  7. TDD Pros and Cons • Pros • Reduce gap between decision and feedback • Encourage developers to write code that is easily tested • Good unit tests can serve as examples and documentation • Drawbacks • Time taken away from core development • Some code is difficult to test Software Engineering Spring 2011