Slide 1

Slide 1 text

Icons made by Icongeek26, Freepik from www.flaticon.com

Slide 2

Slide 2 text

Locking Tests vs. TDD Icons made by Roundicons from www.flaticon.com

Slide 3

Slide 3 text

Icons made by Freepik from www.flaticon.com https://github.com/JMLamodiere/tdd-demo-forumphp2020

Slide 4

Slide 4 text

Previously...

Slide 5

Slide 5 text

● A Functional Test describes a functionality ● A Unit Test locks an implementation Prejudice #1 Icons made by Freepik from www.flaticon.com

Slide 6

Slide 6 text

● A Functional Test describes a behaviour ● A Unit Test locks an implementation Prejudice #1 Icons made by Roundicons from www.flaticon.com All tests describe the expected public behaviour Only the audience and the size of the covered area vary

Slide 7

Slide 7 text

Only functional tests have 3 steps: ● Given ● When ● Then Prejudice #2 Icons made by Freepik from www.flaticon.com

Slide 8

Slide 8 text

Only functional tests have 3 steps: ● Given ● When ● Then Prejudice #2 Icons made by Roundicons from www.flaticon.com All tests follow the narrative structure: ● Given = Arrange ● When = Act ● Then = Assert Setup Catalyst Resolution

Slide 9

Slide 9 text

Prejudice #3 Icons made by Freepik from www.flaticon.com Checking the number of calls to all mocked methods increases my confidence. ->expects($this->exactly(1))->method('xxx') ->shouldBeCalledTimes(1)

Slide 10

Slide 10 text

Prejudice #3 Checking the number of calls to all mocked methods increases my confidence ->expects($this->exactly(1))->method('xxx') ->shouldBeCalledTimes(1) Icons made by Roundicons, Smashicons from www.flaticon.com ● Blurs the intent of the test ● Locks implementation details ● Impossible to write first

Slide 11

Slide 11 text

What to test ?

Slide 12

Slide 12 text

Prejudice #4 Icons made by Freepik from www.flaticon.com I can mock the libraries used on the Infrastructure side : ● Http : Guzzle… ● Database : Doctrine, Eloquent…

Slide 13

Slide 13 text

Prejudice #4 Icons made by Roundicons, Smashicons from www.flaticon.com I can mock the libraries used on the Infrastructure side : ● Http : Guzzle… ● Database : Doctrine, Eloquent… ● Coupled with the usage details of the lib ● Assumptions about the way it behaves ● Impossible to write first

Slide 14

Slide 14 text

Infrastructure : Integration Tests Icons made by Freepik, Smashicons, Roundicons from www.flaticon.com

Slide 15

Slide 15 text

Prejudice #5 Icons made by Freepik from www.flaticon.com Functional Test = necessarily end to end

Slide 16

Slide 16 text

Prejudice #5 Icons made by Roundicons, smashicons from www.flaticon.com Functional Test = necessarily end to end ● Slow ● Brittle ● Difficult to maintain ● Harder to write first ● Locks Infrastructure choices too soon Suggestion : mock Secondary Ports

Slide 17

Slide 17 text

Icons made by Freepik from www.flaticon.com Suggestion

Slide 18

Slide 18 text

I must know the splitting between my classes before I write my tests Prejudice #6 Icons made by Freepik from www.flaticon.com

Slide 19

Slide 19 text

I must know the splitting between my classes before I write my tests Prejudice #6 Icons made by Roundicons from www.flaticon.com ● Prod classes splitting != test classes splitting ● Start with an area with a known boundary

Slide 20

Slide 20 text

Icons made by Freepik from www.flaticon.com 1st test: area with a known boundary

Slide 21

Slide 21 text

Prejudice #7 Icons made by Freepik from www.flaticon.com If I don't mock my Entities / DTOs, too many tests will break if I add a field

Slide 22

Slide 22 text

Prejudice #7 Icons made by Roundicons from www.flaticon.com If I don't mock my Entities / DTOs, too many tests will break if I add a field ● Use test Factori(es) with optional fields ● Getter not covered ? I remove it

Slide 23

Slide 23 text

Thanks! Icons made by Roundicons, Freepik from www.flaticon.com It’s your turn ! ● ●