Test-driven development with PHPUnitOliver Klee, 2022-08@oliklee | Mastodon: [email protected] | [email protected]
View Slide
About meOliver „Oli“ Klee#bonn#extension-dev#workshop-teacher#unit-testing-guy#phpstan-guy#typo3-ombudsperson#typo3-quality-assurance-initiative#gamification-working-group#game-cooking#powermetal
???
The goals✓ You have a clearerunderstanding onhow TDD works.✓(optional) You gettest-infected.✓You learn at least 1new testing pattern.✓We all have fun.
The travel plan1. getting started2. concepts & terms3. testing patterns4. hands-on5. naming tests6. hands-on7. ending & feedback
The rules1. There are nostupid questions.2. The joker rule.
Unit Tests?
Manual testing is cumbersome
Automated testing is fast
Unit tests for the TYPO3 Core
Unit Tests 406 (144) tests/s
Functional Tests 8.13 (1.97) tests/s
Acceptance Tests .009 (.003) tests/s
Verify that your codedoes what you expect
Make sure that your changes won‘t break anything
Keep others from breaking your code
Don’t break anything even in complex projects
Create a safety netfor refactoringor for TYPO3 updates
Improvethe structureof your code
Find the location of bugs
Green feels good!
Let’s get some terms straight
The two programming modescleanhacky
TestsuiteTestcaseTestAssertionTestTestTestcase
The life cycle of a testnew FooTest();setUp();/** @test */lifeIsGood();tearDown();
Code test-firstwrite testwrite coderefactor
https://github.com/TYPO3-Documentation/tea/Branch: workshop/t3dd22File: Exercises.md
Naming Tests
Use meaningful test namesclassCanBeInstantiatedsetTitleSetsTitlesetSizeWithZeroThrowsExceptionhasTitleForEmptyTitleReturnsFalseName thebehavior.Name thepreconditions.Name themethod.Don’t use “works” or “works correctly”.measureFrubbleWorksCorrectly