Slide 1

Slide 1 text

Test-driven 
 Development
 with PHPUnit Oliver Klee, 2018-06 @oliklee [email protected]

Slide 2

Slide 2 text

This is Oliver Klee (me!) Workshop teacher •unit testing •extension development •software quality •saying „no“, consent culture TYPO3 extension
 developer (wanna-be)
 singer @oliklee oliverklee oliverklee.de

Slide 3

Slide 3 text

unterstand TDD become test-infected have fun Workshop goals

Slide 4

Slide 4 text

Workshop Rules

Slide 5

Slide 5 text

Stand up
 for your tests

Slide 6

Slide 6 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 7

Slide 7 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 8

Slide 8 text

Unit
 Tests?

Slide 9

Slide 9 text

Manual testing is cumbersome

Slide 10

Slide 10 text

Automated
 testing
 is fast

Slide 11

Slide 11 text

Unit tests for the
 TYPO3 Core

Slide 12

Slide 12 text

> 4400 tests

Slide 13

Slide 13 text

< 14 seconds

Slide 14

Slide 14 text

Verify that your code does what you expect

Slide 15

Slide 15 text

Make sure that
 your changes won‘t
 break anything

Slide 16

Slide 16 text

Keep others
 from breaking your code

Slide 17

Slide 17 text

Don’t break anything
 even in complex
 projects

Slide 18

Slide 18 text

Create a safety net for refactoring or for
 TYPO3 updates

Slide 19

Slide 19 text

Improve the structure of your code

Slide 20

Slide 20 text

Green feels good!

Slide 21

Slide 21 text

https://github.com/oliverklee/tdd-reader
 /Exercises/tdd-exercises-en.md

Slide 22

Slide 22 text

Let’s get
 some terms
 straight

Slide 23

Slide 23 text

The two programming modes clean hacky

Slide 24

Slide 24 text

Testsuite Testcase Test Assertion Test Test Testcase

Slide 25

Slide 25 text

The life cycle of a test new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();

Slide 26

Slide 26 text

4 test phases set up setUp()
 code in the test method exercise method call verify assert…() tear down tearDown()

Slide 27

Slide 27 text

Code test-first write
 test write
 code refactor

Slide 28

Slide 28 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 29

Slide 29 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

https://github.com/oliverklee/tdd-reader
 /Exercises/tdd-exercises-en.md

Slide 32

Slide 32 text

Test levels http://filipdefar.com/2015/06/tested-be-thy-name.html

Slide 33

Slide 33 text

Unit tests are small and fast

Slide 34

Slide 34 text

Integration tests test how components work together in TYPO3:
 „functional tests“

Slide 35

Slide 35 text

Systemtests test the big picture

Slide 36

Slide 36 text

Test types

Slide 37

Slide 37 text

Blackbox tests test the public API

Slide 38

Slide 38 text

Whitebox tests inner workings test the

Slide 39

Slide 39 text

Functional
 tests

Slide 40

Slide 40 text

Acceptance tests Selenium Codeception

Slide 41

Slide 41 text

Anti-
 zombie tests-

Slide 42

Slide 42 text

Regression tests

Slide 43

Slide 43 text

Smoke tests

Slide 44

Slide 44 text

Smoke tests

Slide 45

Slide 45 text

Story tests for Behavior-driven development (BDD) Behat Codeception

Slide 46

Slide 46 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 47

Slide 47 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 48

Slide 48 text

Naming
 Tests

Slide 49

Slide 49 text

Use meaningful test names classCanBeInstantiated setTitleSetsTitle setSizeWithZeroThrowsException hasTitleForEmptyTitleReturnsFalse Name the behavior. Name the preconditions. Name the method. Don’t use
 “works” or
 “works correctly”. measureFrubbleWorksCorrectly

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 52

Slide 52 text

Workshop roadmap 1. Terms & concepts 2. Testing patterns 3. Naming things 4. Code katas

Slide 53

Slide 53 text

No content