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

Getting started with TDD

Patkos Csaba
November 18, 2014

Getting started with TDD

A short talk I use to present for people curious about understanding the basics of TDD

Patkos Csaba

November 18, 2014
Tweet

More Decks by Patkos Csaba

Other Decks in Technology

Transcript

  1. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    4/24 STRUCTURE PART 1 – About testing in general. PART 2 – Test Driven Development explained. PART 3 – A short live example.
  2. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    5/24 AUTOMATED TESTING In software testing, test automation is the use of special software (separate from the software being tested) to control the execution of tests and the comparison of actual outcomes with predicted outcomes. Source Wikipedia
  3. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    7/24 DIFFERENT TEST TYPES U N I T T E S T S M.T. E2E A.P.I. TESTS INTEGRATION TESTS COMPONENT TESTS
  4. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    9/24 MANUAL AND END-TO-END TESTS M ANUAL & E2E TEST BACKDOOR VERIFICATION FRONTDOOR VERIFICATION
  5. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    11/24 INTEGRATION TESTS Business Logic INTEGRATION TESTS C C C C C
  6. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    12/24 COMPONENT TESTS Business Logic C C C COMPONENT CLASS CLASS CLASS CLASS CLASS COM PONENT TESTS
  7. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    13/24 UNIT TESTS Business Logic COMPONENT CLASS CLASS CLASS CLASS CLASS PUBLIC METHOD PUBLIC METHOD PR . ME. PR . ME. PR . ME. PR . ME. PR . ME. PR . ME. U N I T T E S T S
  8. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    14/24 A SIMPLE UNIT TEST EXAMPLE Set Up Exercise Verify
  9. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    16/24 FROM CODE TO TEST AND BACK AGAIN COMPLICATED CODE IMPOSSIBLE TEST SIMPLE CODE EASY TESTING SIMPLE TESTS SIMPLE CODE
  10. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    17/24 THE THREE LAWS OF TEST DRIVEN DEVELOPMENT 1.You are not allowed to write any production code unless it is to make a failing unit test pass. 2.You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. 3.You are not allowed to write any more production code than is sufficient to pass the one failing unit test. Robert C. Martin
  11. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    18/24 THE THREE STAGED CYCLE OF TEST DRIVEN DEVELOPMENT R E D GREEN REFACTOR 1. Write Test 2. Fail the Test 3. Write Production Code 4. Pass the Test 5. Refactor both Test and Productin Code 6. Ensure Tests are Still Passing
  12. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    19/24 IT'S TIME FOR A LIVE DEMO THE FIZZBUZZ EXERCISE https://en.wikipedia.org/wiki/Fizz_buzz
  13. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    20/24 TESTING OBJECT COLLABORATION SmartCar Steering SpeedControl
  14. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    21/24 TEST STUB We replace a real object with a test-specific object that feeds the desired indirect inputs into the system under test. Gerard Meszaros
  15. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    22/24 TEST SPY We use a Test Double to capture the indirect output calls made to another component by the SUT for later verification by the test. Gerard Meszaros
  16. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    23/24 TEST MOCK We replace an object on which the SUT depends on with a test-specific object that verifies it is being used correctly by the SUT. Gerard Meszaros
  17. 2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com

    24/24 TEST FAKE We replace a component that the SUT depends on with a much lighter-weight implementation. Gerard Meszaros