Share
Embed
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
Transcript
24 slides
-
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
2/24 HIGH LEVEL ARCHITECTURE -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
3/24 ABOUT PATKÓS CSABA -
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. -
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 -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
6/24 AUTOMATED TESTING TEST CODE PRODUCTION CODE -
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 -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
8/24 HIGH LEVEL ARCHITECTURE -
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 -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
10/24 A.P .I. TESTS A.P.I. TESTS A.P.I. TESTS X X X -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
11/24 INTEGRATION TESTS Business Logic INTEGRATION TESTS C C C C C -
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 -
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 -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
14/24 A SIMPLE UNIT TEST EXAMPLE Set Up Exercise Verify -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
15/24 WHAT ABOUT COMPLEX METHODS? -
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 -
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 -
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 -
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 -
2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com
20/24 TESTING OBJECT COLLABORATION SmartCar Steering SpeedControl -
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 -
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 -
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 -
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