Slide 1

Slide 1 text

Getting Started with Test Driven Development

Slide 2

Slide 2 text

2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com 2/24 HIGH LEVEL ARCHITECTURE

Slide 3

Slide 3 text

2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com 3/24 ABOUT PATKÓS CSABA

Slide 4

Slide 4 text

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.

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com 6/24 AUTOMATED TESTING TEST CODE PRODUCTION CODE

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com 8/24 HIGH LEVEL ARCHITECTURE

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

2014 – Patkós Csaba / [email protected] / @PatkosCsaba / patkoscsaba.blogspot.com 15/24 WHAT ABOUT COMPLEX METHODS?

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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