Test locks an implementation Prejudice #1 Icons made by Roundicons from www.flaticon.com All tests describe an expected public behaviour Only the audience and the size of the covered area vary Test Desiderata - Kent Beck : https://kentbeck.github.io/TestDesiderata/
Icons made by Roundicons, Smashicons from www.flaticon.com Polysemy! Wrong debate... “A DeveloperTest is the correct name for what the industry generally calls a UnitTest” - Ward Cunningham The Unit Test trap : https://drpicox.medium.com/the-unit-test-trap-4a83e4012b17
Test = mock other classes Prejudice #3 Icons made by Roundicons, Smashicons from www.flaticon.com Favor fast and focused tests. Ex: The Practical Test Pyramid : https://martinfowler.com/articles/practical-test-pyramid.html Slow Fast, Focus Sociable Unit Test UI component test Unit Tests on Adapters
• Then Prejudice #4 Icons made by Roundicons from www.flaticon.com All tests follow the narrative structure: • Given = Arrange • When = Act • Then = Assert Setup Catalyst Resolution
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
Arguments (IN) Return value (OUT) Test Calls Collaborator (IN) Collaborator (OUT) Assert Stub : willReturn() Spy : shouldHaveBeenCalled() Given When Then Then
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
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 • No confidence when upgrading the lib
Test = necessarily end to end • Slow • Brittle • Difficult to maintain • Harder to write first • Locks Infrastructure choices too soon Suggestion : mock Secondary Ports
by Roundicons, Freepik from www.flaticon.com It’s your turn ! • //Given //When //Then • Even if I write a test afterwards, I only write what I would have been sure of before https://github.com/JMLamodiere/tdd-demo-forumphp2020 https://github.com/JMLamodiere/tdd-demo-swcraftlyon-scala @swcraftlyon